2016-03-08 20:29:35 -07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Code in this script is derived from OpenWRT
|
|
|
|
# GPLv2 License
|
|
|
|
|
|
|
|
kill_remaining() { # [ <signal> ]
|
|
|
|
local sig="${1:-TERM}"
|
2016-06-16 18:32:29 -06:00
|
|
|
printf "Sending %s to remaining processes ... " "$sig"
|
2016-03-08 20:29:35 -07:00
|
|
|
|
|
|
|
local my_pid=$$
|
2016-06-16 18:32:29 -06:00
|
|
|
local my_ppid
|
|
|
|
my_ppid=$(cut -d' ' -f4 /proc/$my_pid/stat)
|
2016-03-08 20:29:35 -07:00
|
|
|
local my_ppisupgraded=
|
2016-06-16 18:32:29 -06:00
|
|
|
grep -q upgraded "/proc/$my_ppid/cmdline" >/dev/null && {
|
2016-03-08 20:29:35 -07:00
|
|
|
local my_ppisupgraded=1
|
|
|
|
}
|
2016-06-16 18:32:29 -06:00
|
|
|
|
2016-03-08 20:29:35 -07:00
|
|
|
local stat
|
|
|
|
for stat in /proc/[0-9]*/stat; do
|
|
|
|
[ -f "$stat" ] || continue
|
|
|
|
|
2016-06-16 18:32:29 -06:00
|
|
|
local pid name _ ppid rest
|
|
|
|
read pid name _ ppid rest < "$stat"
|
2016-03-08 20:29:35 -07:00
|
|
|
name="${name#(}"; name="${name%)}"
|
|
|
|
|
|
|
|
local cmdline
|
2016-06-16 18:32:29 -06:00
|
|
|
read cmdline < "/proc/$pid/cmdline"
|
2016-03-08 20:29:35 -07:00
|
|
|
|
|
|
|
# Skip kernel threads
|
|
|
|
[ -n "$cmdline" ] || continue
|
|
|
|
|
2016-06-16 18:32:29 -06:00
|
|
|
if [ $$ -eq 1 ] || [ "$my_ppid" -eq 1 ] && [ -n "$my_ppisupgraded" ]; then
|
2016-03-08 20:29:35 -07:00
|
|
|
# Running as init process, kill everything except me
|
2016-06-16 18:32:29 -06:00
|
|
|
if [ "$pid" -ne $$ ] && [ "$pid" -ne "$my_ppid" ]; then
|
|
|
|
printf "%s " "$name"
|
|
|
|
kill "-$sig" "$pid" 2>/dev/null
|
2016-03-08 20:29:35 -07:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
case "$name" in
|
|
|
|
# Skip essential services
|
|
|
|
*procd*|*ash*|*init*|*ssh*|*dropbear*|*login*|*uhttpd*|*admin*|*sysupgrade*|*upgrade_kill_prep*|*olsr*|*ubusd*) : ;;
|
|
|
|
|
|
|
|
# Killable process
|
|
|
|
*)
|
2016-06-16 18:32:29 -06:00
|
|
|
if [ "$pid" -ne $$ ] && [ "$ppid" -ne $$ ]; then
|
|
|
|
printf "%s " "$name"
|
|
|
|
kill "-$sig" "$pid" 2>/dev/null
|
2016-03-08 20:29:35 -07:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
2018-11-27 20:08:30 -07:00
|
|
|
/etc/init.d/cron stop
|
2016-03-08 20:29:35 -07:00
|
|
|
kill_remaining TERM
|
2016-05-10 20:22:33 -06:00
|
|
|
sleep 3
|
2016-03-08 20:29:35 -07:00
|
|
|
kill_remaining KILL
|
2016-05-10 20:22:33 -06:00
|
|
|
sleep 1
|