fifo/lock fixes

This commit is contained in:
Kolan Sh 2012-03-21 00:15:32 +04:00
parent 7c4f48df57
commit 7d36cbda32
4 changed files with 44 additions and 41 deletions

View File

@ -1,8 +1,9 @@
#!/sbin/runscript
DAEMON="/usr/local/sbin/snail.watcher"
DAEMON="/usr/local/sbin/snail.watcher.sh"
DAEMON_ARGS=""
PIDFILE=/var/run/snail.pid
#PATH=/usr/local/sbin:/usr/local/bin:$PATH
PATH=$PATH:/usr/local/bin
depend() {
@ -11,16 +12,19 @@ depend() {
start() {
ebegin "Starting ${SVCNAME}"
start-stop-daemon -m -b --start --exec $DAEMON \
--pidfile $PIDFILE \
-- $DAEMON_ARGS
start-stop-daemon --make-pidfile \
--background \
--start \
--exec $DAEMON \
--pidfile $PIDFILE \
-- $DAEMON_ARGS
eend $?
}
stop() {
ebegin "Stopping ${SVCNAME}"
start-stop-daemon --stop --exec $DAEMON \
--pidfile $PIDFILE
start-stop-daemon --stop \
--exec $DAEMON \
--pidfile $PIDFILE
eend $?
}

View File

@ -2,7 +2,7 @@
PATH=/usr/local/sbin:/usr/local/bin:$PATH
TIMEOUT=5 # wait timeout for X server start
TIMEOUT=10 # wait timeout for X server start
let INTEL_IF_FAIL=1 # run on Intel if nVidia fails
SERVICE=/etc/init.d/snail-xserver
@ -13,7 +13,7 @@ FIFO_FILE=/tmp/.snail.fifo
{
echo -n >$FIFO_FILE
echo -n > $FIFO_FILE &
flock -w $TIMEOUT -s 9
if [ 0 -eq $? ]; then
@ -27,4 +27,6 @@ FIFO_FILE=/tmp/.snail.fifo
echo "Application $@ was performed on Intel"
fi
} 9 > $LOCK_FILE
flock -u 9
} 9>$LOCK_FILE

View File

@ -1,31 +0,0 @@
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:$PATH
SERVICE=/etc/init.d/snail-xserver
PROC=nvrun
LOCK_FILE=/tmp/.snail.lock
FIFO_FILE=/tmp/.snail.fifo
$SERVICE stop && snail.nv_pwr_off # stop X service
touch $LOCK_FILE && chown 0:0 $LOCK_FILE # create lock file
rm -f $FIFO_FILE && mkfifo --mode 640 $FIFO_FILE && chgrp video $FIFO_FILE # create fifo
{
echo >$FIFO_FILE | cat <$FIFO_FILE >/dev/null # flush fifo
flock -n 9 # make exclusive lock
while [ 1 ]; do
cat <$FIFO_FILE >/dev/null
flock -u 9 # unlock to get access for clients
flock -n 9
if [ 0 -ne $? ]; then # test is $LOCK_FILE locked by any client
snail.nv_pwr_on && $SERVICE start # starting X server
flock 9
echo >$FIFO_FILE | cat <$FIFO_FILE >/dev/null # flush fifo
$SERVICE stop && snail.nv_pwr_off # stopping X server
fi
done
} 9 > $LOCK_FILE

28
usr/local/sbin/snail.watcher.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:$PATH
SERVICE=/etc/init.d/snail-xserver
PROC=nvrun
LOCK_FILE=/tmp/.snail.lock
FIFO_FILE=/tmp/.snail.fifo
$SERVICE stop && snail.nv_pwr_off # stop X service
touch $LOCK_FILE && chown root:video $LOCK_FILE && chmod 660 $LOCK_FILE # create lock file
rm -f $FIFO_FILE && mkfifo --mode 660 $FIFO_FILE && chgrp video $FIFO_FILE # create fifo
{
echo >$FIFO_FILE | cat $FIFO_FILE >/dev/null # flush fifo
flock -n 9 # make exclusive lock
while [ 1 ]; do
read <$FIFO_FILE
snail.nv_pwr_on && $SERVICE start # starting X server
flock -u 9
flock 9
echo >$FIFO_FILE | cat $FIFO_FILE >/dev/null # flush fifo
$SERVICE stop && snail.nv_pwr_off # stopping X server
done
} 9>$LOCK_FILE