Currently /lib/upgrade/common.sh contains a static list of essential processes that shouldn't be killed during sysupgrade. This changes that static list into a dynamic one built from a ESSENTIAL_PROCESSES shell variable in package init scripts. That way, packages can declare their own essential processes. There's a corresponding patch for the packages repo.
* add /etc/rc.common listessential action * modify /lib/upgrade/common.sh to query essential processes * add ESSENTIAL_PROCESSES to appropriate init scripts Signed-off-by: Ryan Nowakowski <tuba...@fattuba.com> --- package/base-files/files/etc/rc.common | 8 +++++++- package/base-files/files/lib/upgrade/common.sh | 25 +++++++++++++++++++++--- package/busybox/files/telnet | 1 + package/dropbear/files/dropbear.init | 1 + package/netifd/files/etc/init.d/network | 1 + package/ubus/files/ubus.init | 1 + 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common index fa2df6c..092f0d7 100755 --- a/package/base-files/files/etc/rc.common +++ b/package/base-files/files/etc/rc.common @@ -56,6 +56,11 @@ enabled() { [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ] } +listessential() { + name="$(basename "${initscript}")" + [ "$ESSENTIAL_PROCESSES" ] && echo "$ESSENTIAL_PROCESSES" +} + depends() { return 0 } @@ -71,6 +76,7 @@ Available commands: reload Reload configuration files (or restart if that fails) enable Enable service autostart disable Disable service autostart + listessential List the essential processes for sysupgrade $EXTRA_HELP EOF } @@ -79,7 +85,7 @@ ${INIT_TRACE:+set -x} . "$initscript" -ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}" +ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends listessential ${EXTRA_COMMANDS}" list_contains ALL_COMMANDS "$action" || action=help [ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :' $action "$@" diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index e6de348..ce77845 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -5,6 +5,25 @@ RAM_ROOT=/tmp/root ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } libs() { ldd $* | awk '{print $3}'; } +get_essential_processes() { + for script in /etc/init.d/*; do + grep '#!/bin/sh /etc/rc.common' $script >/dev/null || continue + sh /etc/rc.common $script listessential + done +} + +ESSENTIAL="$(get_essential_processes)" + +is_essential() { + local process=$1 + for p in $ESSENTIAL; do + if [ "$process" == "$p" ]; then + return 0 + fi + done + return 1 +} + install_file() { # <file> [ <file> ... ] for file in "$@"; do dest="$RAM_ROOT/$file" @@ -98,12 +117,12 @@ kill_remaining() { # [ <signal> ] [ -n "$cmdline" ] || continue case "$name" in - # Skip essential services - *ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*) : ;; + # Skip essential core services + *ash*|*init*|*watchdog*|*login*) : ;; # Killable process *) - if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then + if [ $pid -ne $$ ] && [ $ppid -ne $$ ] && ! is_essential $name; then echo -n "$name " kill -$sig $pid 2>/dev/null fi diff --git a/package/busybox/files/telnet b/package/busybox/files/telnet index 994e713..e08a94d 100755 --- a/package/busybox/files/telnet +++ b/package/busybox/files/telnet @@ -2,6 +2,7 @@ # Copyright (C) 2006-2011 OpenWrt.org START=50 +ESSENTIAL_PROCESSES="telnet telnetd" has_root_pwd() { local pwd=$([ -f "$1" ] && cat "$1") diff --git a/package/dropbear/files/dropbear.init b/package/dropbear/files/dropbear.init index c909d28..cf45190 100755 --- a/package/dropbear/files/dropbear.init +++ b/package/dropbear/files/dropbear.init @@ -4,6 +4,7 @@ START=50 STOP=50 +ESSENTIAL_PROCESSES="dropbear" SERVICE_USE_PID=1 diff --git a/package/netifd/files/etc/init.d/network b/package/netifd/files/etc/init.d/network index ea93819..8595812 100755 --- a/package/netifd/files/etc/init.d/network +++ b/package/netifd/files/etc/init.d/network @@ -2,6 +2,7 @@ START=20 STOP=90 +ESSENTIAL_PROCESSES="netifd hostapd wpa_supplicant udhcpc" SERVICE_DAEMONIZE=1 SERVICE_WRITE_PID=1 diff --git a/package/ubus/files/ubus.init b/package/ubus/files/ubus.init index 70fe21c..8d09af6 100755 --- a/package/ubus/files/ubus.init +++ b/package/ubus/files/ubus.init @@ -1,6 +1,7 @@ #!/bin/sh /etc/rc.common START=11 +ESSENTIAL_PROCESSES="ubusd" SERVICE_DAEMONIZE=1 SERVICE_WRITE_PID=1 -- 1.7.9.5 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel