X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=package%2Fbase-files%2Ffiles%2Flib%2Fupgrade%2Fcommon.sh;h=8cdabc6bdaea1cb2c892d656979c8b7c808cf05c;hb=8720bd8dcafdd733159269da1c39aa7db0217756;hp=91e61ba4f8bc0c89b506394e14807ad4a86fd3c2;hpb=4323c101fcd011732835ecf8785b3c92e3ea20de;p=openwrt.git diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index 91e61ba4f8..8cdabc6bda 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -2,8 +2,8 @@ RAM_ROOT=/tmp/root -ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } -libs() { ldd $* | awk '{print $3}'; } +[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } +libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; } install_file() { # [ ... ] for file in "$@"; do @@ -21,9 +21,6 @@ install_bin() { # [ ... ] files=$1 [ -x "$src" ] && files="$src $(libs $src)" install_file $files - [ -e /lib/ld.so.1 ] && { - install_file /lib/ld.so.1 - } shift for link in "$@"; do { dest="$RAM_ROOT/$link" @@ -59,7 +56,6 @@ run_ramfs() { # [...] /bin/rm /usr/bin/basename /bin/kill /bin/chmod install_bin /sbin/mtd - install_bin /sbin/ubi install_bin /sbin/mount_root install_bin /sbin/snapshot install_bin /sbin/snapshot_tool @@ -74,7 +70,9 @@ run_ramfs() { # [...] for file in $RAMFS_COPY_BIN; do install_bin ${file//:/ } done - install_file /etc/resolv.conf /lib/functions.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA + install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA + + [ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64 supivot $RAM_ROOT /mnt || { echo "Failed to switch over to ramfs. Please reboot." @@ -97,6 +95,13 @@ kill_remaining() { # [ ] 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 @@ -111,18 +116,26 @@ kill_remaining() { # [ ] # Skip kernel threads [ -n "$cmdline" ] || continue - 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 + 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 "" }