[oe-commits] [openembedded-core] 01/11: sysklogd: Fix init script races

git at git.openembedded.org git at git.openembedded.org
Mon Jun 24 16:21:52 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit f51c2ea51ad52087bff0dc7f402859ba5e32097d
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Mon Jun 24 16:41:45 2019 +0100

    sysklogd: Fix init script races
    
    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 at linuxfoundation.org>
---
 meta/recipes-extended/sysklogd/files/sysklogd | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/meta/recipes-extended/sysklogd/files/sysklogd b/meta/recipes-extended/sysklogd/files/sysklogd
index 258f882..7342484 100755
--- a/meta/recipes-extended/sysklogd/files/sysklogd
+++ b/meta/recipes-extended/sysklogd/files/sysklogd
@@ -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 $?
     ;;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list