From fa72d5a17504e50b80eface976f7956405eb4cba Mon Sep 17 00:00:00 2001 From: Kenneth Chan Date: Fri, 4 Sep 2020 00:43:53 +0700 Subject: system/sleepd: Fix bug. Signed-off-by: Willy Sudiarto Raharjo --- system/sleepd/rc.sleepd | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'system/sleepd/rc.sleepd') diff --git a/system/sleepd/rc.sleepd b/system/sleepd/rc.sleepd index bbfa1b0f15..66587a2f8c 100644 --- a/system/sleepd/rc.sleepd +++ b/system/sleepd/rc.sleepd @@ -1,26 +1,36 @@ #!/bin/sh # /etc/rc.d/rc.sleepd -# Start/stop/restart the Wicd daemon +# Start/stop/restart the sleepd daemon PIDFILE="/var/run/sleepd.pid" DAEMON="/usr/sbin/sleepd" +. /etc/sleepd.conf + # Define start and stop functions sleepd_start() { + [ $UID -eq 0 ] || exit 4 if [ -e $PIDFILE ]; then - echo "sleepd appears to already be running." - echo "If this is not the case, then remove " - echo "$PIDFILE and try again..." + echo "sleepd appears to already be running. If this is not the case," + echo "remove $PIDFILE and try again." exit 1 else - echo "Starting sleepd: $DAEMON &" - sleepd 2>/dev/null 1>&2 & + echo "Starting sleepd: $DAEMON" + sleepd $PARAMS > /dev/null 2>&1 + ps -p `cat $PIDFILE` > /dev/null 2>&1 + if [ "$?" == 1 ]; then + rm -f $PIDFILE + echo "ERROR: $DAEMON failed to start." + echo "ERROR: For more verbosity, run \"$DAEMON -n -v\" manually." + echo "ERROR: Exiting..." + fi fi } sleepd_force_stop() { + [ $UID -eq 0 ] || exit 4 echo "Force stopping sleepd..." if [ -e $PIDFILE ]; then kill $(cat $PIDFILE) 2>/dev/null @@ -31,6 +41,7 @@ sleepd_force_stop() { } sleepd_stop() { + [ $UID -eq 0 ] || exit 4 echo "Stopping sleepd..." if [ -e $PIDFILE ]; then kill $(cat $PIDFILE) 2>/dev/null @@ -62,7 +73,7 @@ case $1 in sleepd_status ;; *) - echo "Usage: $0 {start|stop|restart|status}" + echo "Usage: $0 {start|stop|force_stop|restart|status}" exit 1 ;; esac -- cgit v1.2.3