diff options
author | John Crispin <blogic@openwrt.org> | 2014-07-10 19:16:27 +0000 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2014-07-10 19:16:27 +0000 |
commit | 0126e7505eade8497c8fff9efc302b875450b081 (patch) | |
tree | 3258a3be3120f3efaec89f8ff53263814439f8b1 /package/base-files/files | |
parent | 8b5f2129984c6c31d2a9fe74733cdc553dba68fc (diff) | |
download | master-187ad058-0126e7505eade8497c8fff9efc302b875450b081.tar.gz master-187ad058-0126e7505eade8497c8fff9efc302b875450b081.tar.bz2 master-187ad058-0126e7505eade8497c8fff9efc302b875450b081.zip |
sysupgrade: Enable killing of all processes under upgraded
If the sysupgrade scripts is called under upgraded, it will not kill all
other processes as it should to avoid interference by locked filesystem.
This patch checks the parent and if it is upgraded, it kills all.
Signed-off-by: André Valentin <avalentin@marcant.net>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@41563 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/base-files/files')
-rw-r--r-- | package/base-files/files/lib/upgrade/common.sh | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index 6f1880fba6..ba9de99dc9 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -99,6 +99,13 @@ kill_remaining() { # [ <signal> ] local sig="${1:-TERM}" echo -n "Sending $sig to remaining processes ... " + local my_pid=$$ + local my_ppid=$(cut -d' ' -f4 /proc/$my_pid/stat) + local my_ppisupgraded= + grep -q upgraded /proc/$my_ppid/cmdline >/dev/null && { + local my_ppisupgraded=1 + } + local stat for stat in /proc/[0-9]*/stat; do [ -f "$stat" ] || continue @@ -113,18 +120,26 @@ kill_remaining() { # [ <signal> ] # Skip kernel threads [ -n "$cmdline" ] || continue - case "$name" in - # Skip essential services - *procd*|*upgraded*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*) : ;; - - # Killable process - *) - if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then - echo -n "$name " - kill -$sig $pid 2>/dev/null - fi - ;; - esac + if [ $$ -eq 1 ] || [ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then + # Running as init process, kill everything except me + if [ $pid -ne $$ ] && [ $pid -ne $my_ppid ]; then + echo -n "$name " + kill -$sig $pid 2>/dev/null + fi + else + case "$name" in + # Skip essential services + *procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*) : ;; + + # Killable process + *) + if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then + echo -n "$name " + kill -$sig $pid 2>/dev/null + fi + ;; + esac + fi done echo "" } |