annotate rlgwebd @ 165:59e62710cbb5

rlgwebd.js: prevent races when reading ttyrecs. DglSession objects read a 12-byte TTYREC header, extract therefrom the length of the data chunk, and then read the data. In between these two reads, the file watcher could trigger another readchunk() invocation, which might attempt to read a header from the beginning of the data chunk. This usually results in expecting a data chunk of several GB and failing to create a Buffer for it. The race is remedied by setting a flag on the DglSession object whenever readchunk() is called, clearing it when both reads complete, and refusing to read if it is already set.
author John "Elwin" Edwards
date Wed, 07 Jan 2015 13:18:35 -0500
parents 1a156a7746a7
children 5483d413a45b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
139
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
1 #!/bin/sh
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
2
141
1a156a7746a7 RLGWebD: use NODE_PATH to find modules.
John "Elwin" Edwards
parents: 139
diff changeset
3 NODE_PATH=/usr/lib/node_modules
139
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
4 LOGFILE=/var/local/rlgwebd/log
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
5 CTLSOCKET=/var/local/rlgwebd/ctl
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
6 RLGWEBDJS=./rlgwebd.js
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
7
141
1a156a7746a7 RLGWebD: use NODE_PATH to find modules.
John "Elwin" Edwards
parents: 139
diff changeset
8 export NODE_PATH
1a156a7746a7 RLGWebD: use NODE_PATH to find modules.
John "Elwin" Edwards
parents: 139
diff changeset
9
139
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
10 if [ $UID != 0 ]
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
11 then
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
12 echo "$0 needs to run as root." >&2
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
13 exit 1
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
14 fi
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
15
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
16 if [ $# -gt 0 ] && [ $1 = stop ]
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
17 then
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
18 socat "EXEC:echo quit" "$CTLSOCKET"
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
19 else
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
20 # Start
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
21 setsid node "$RLGWEBDJS" </dev/null &>>$LOGFILE &
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
22 fi
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
23
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
24 exit
dcd07c1d846a Replace the daemon module with posix.
John "Elwin" Edwards
parents:
diff changeset
25