view 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
line wrap: on
line source

#!/bin/sh

NODE_PATH=/usr/lib/node_modules
LOGFILE=/var/local/rlgwebd/log
CTLSOCKET=/var/local/rlgwebd/ctl
RLGWEBDJS=./rlgwebd.js

export NODE_PATH

if [ $UID != 0 ]
then
  echo "$0 needs to run as root." >&2
  exit 1
fi

if [ $# -gt 0 ] && [ $1 = stop ]
then
  socat "EXEC:echo quit" "$CTLSOCKET"
else
  # Start
  setsid node "$RLGWEBDJS" </dev/null &>>$LOGFILE &
fi

exit