From 4856be4ef18271fb8d005bcc44ebc376a5372c7a Mon Sep 17 00:00:00 2001 From: bol-van Date: Sat, 23 Nov 2024 10:58:46 +0300 Subject: [PATCH] init.d: do not use pgrep for firmwares compatibility --- init.d/sysv/functions | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/init.d/sysv/functions b/init.d/sysv/functions index 0897607..7965372 100644 --- a/init.d/sysv/functions +++ b/init.d/sysv/functions @@ -167,9 +167,15 @@ run_daemon() # use $PIDDIR/$DAEMONBASE$1.pid as pidfile local DAEMONBASE="$(basename "$2")" - local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid + local PID= PIDFILE=$PIDDIR/$DAEMONBASE$1.pid echo "Starting daemon $1: $2 $3" - if [ -f "$PIDFILE" ] && pgrep -F "$PIDFILE" "$DAEMONBASE" >/dev/null; then + + [ -f "$PIDFILE" ] && { + read PID <"$PIDFILE" + [ -d "/proc/$PID" ] || PID= + } + + if [ -n "$PID" ]; then echo already running else "$2" $3 >/dev/null & @@ -188,18 +194,14 @@ stop_daemon() # $2 - daemon # use $PIDDIR/$DAEMONBASE$1.pid as pidfile local DAEMONBASE="$(basename "$2")" - local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid + local PID PIDFILE=$PIDDIR/$DAEMONBASE$1.pid echo "Stopping daemon $1: $2" - if exists start-stop-daemon ; then - start-stop-daemon -K -p "$PIDFILE" -x "$2" + if [ -f "$PIDFILE" ]; then + read PID <"$PIDFILE" + kill $PID + rm -f "$PIDFILE" else - if [ -f "$PIDFILE" ]; then - read PID <"$PIDFILE" - kill $PID - rm -f "$PIDFILE" - else - echo no pidfile : $PIDFILE - fi + echo no pidfile : $PIDFILE fi } do_daemon()