base-files: upgrade: don't loop forever trying to kill processes
authorMatthias Schiffer <mschiffer@universe-factory.net>
Wed, 12 Jul 2017 22:19:32 +0000 (00:19 +0200)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Thu, 20 Jul 2017 19:41:33 +0000 (21:41 +0200)
When processes don't die on SIGKILL (usually because of kernel bugs), it's
better to give up instead of looping forever.

upgraded will trigger a reboot in this case (and if this fails, a hardware
watchdog will eventually time out and reset the system, if present).

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
package/base-files/files/lib/upgrade/stage2

index 5a439f1..d7f92a4 100755 (executable)
@@ -78,6 +78,8 @@ switch_to_ramfs() {
 }
 
 kill_remaining() { # [ <signal> [ <loop> ] ]
+       local loop_limit=10
+
        local sig="${1:-TERM}"
        local loop="${2:-0}"
        local run=true
@@ -108,8 +110,15 @@ kill_remaining() { # [ <signal> [ <loop> ] ]
 
                        [ $loop -eq 1 ] && run=true
                done
+
+               let loop_limit--
+               [ $loop_limit -eq 0 ] && {
+                       echo
+                       echo "Failed to kill all processes."
+                       exit 1
+               }
        done
-       echo ""
+       echo
 }