]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
sysklogd: Fix init script races
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 24 Jun 2019 15:41:45 +0000 (16:41 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 27 Jun 2019 11:20:24 +0000 (12:20 +0100)
In testing we're seeing sysklogd fail to restart klogd since the original
process hasn't stopped before the new one is started. This means a restart
can result in no process running which is clearly not desireable.

Add extra code to ensure this works correctly. Busybox start-stop-daemon
seems particularly open to this kind of issue, the dpkg version maybe
less so if timeout options are used (which we don't use).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-extended/sysklogd/files/sysklogd

index 258f8828039f92dba4dceb1e2a0221d898512657..73424840ba35caf4ed290aca6b3b2b747f7bf066 100755 (executable)
@@ -90,6 +90,22 @@ running()
     return 0
 }
 
+waitpid ()
+{
+  pid=$1
+  # Give pid a chance to exit before we restart with a 5s timeout in 1s intervals
+  if [ -z "$pid" ]; then
+    return
+  fi
+  timeout=5;
+  while [ $timeout -gt 0 ]
+  do
+    timeout=$(( $timeout-1 ))
+    kill -0 $pid 2> /dev/null || break
+    sleep 1
+  done
+}
+
 case "$1" in
   start)
     log_begin_msg "Starting system log daemon..."
@@ -113,17 +129,23 @@ case "$1" in
     start-stop-daemon --stop --quiet --signal 1 --pidfile $pidfile_syslogd --name syslogd
     log_end_msg $?
     log_begin_msg "Reloading kernel log daemon..."
+    pid=`cat $pidfile_klogd 2> /dev/null`
     start-stop-daemon --stop --quiet --retry 3 --exec $binpath_klogd --pidfile $pidfile_klogd
+    waitpid $pid
     start-stop-daemon --start --quiet --pidfile $pidfile_klogd --name klogd --startas $binpath_klogd -- $KLOGD
     log_end_msg $?
     ;;
   restart)
     log_begin_msg "Restarting system log daemon..."
+    pid=`cat $pidfile_syslogd 2> /dev/null`
     start-stop-daemon --stop --retry 5 --quiet --pidfile $pidfile_syslogd --name syslogd
+    waitpid $pid
     start-stop-daemon --start --quiet --pidfile $pidfile_syslogd --name syslogd --startas $binpath_syslogd -- $SYSLOGD
     log_end_msg $?
     log_begin_msg "Reloading kernel log daemon..."
+    pid=`cat $pidfile_klogd 2> /dev/null`
     start-stop-daemon --stop --quiet --retry 3 --exec $binpath_klogd --pidfile $pidfile_klogd
+    waitpid $pid
     start-stop-daemon --start --quiet --pidfile $pidfile_klogd --name klogd --startas $binpath_klogd -- $KLOGD
     log_end_msg $?
     ;;