X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=package%2Fbase-files%2Ffiles%2Flib%2Fupgrade%2Fcommon.sh;h=ea03f7761f3326f9db3f8b54e561757f8de1dfa6;hp=b641f55156bca7053495be025feb0e669891ebe4;hb=e1406cd31a598b48350e0c012dc177c5b752d05b;hpb=09273f5c0acdfefdcab4eb44fdfbfea11ce2921a diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index b641f55156..ea03f7761f 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" @@ -51,15 +48,15 @@ supivot() { # run_ramfs() { # [...] install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \ - /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd \ - /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" \ - /bin/dd /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump \ + /sbin/pivot_root /sbin/reboot /bin/sync /bin/dd /bin/grep \ + /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/dd \ + /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump \ /bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \ /bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir \ - /bin/rm /usr/bin/basename /bin/kill /bin/chmod + /bin/rm /usr/bin/basename /bin/kill /bin/chmod /usr/bin/find + install_bin /bin/uclient-fetch /bin/wget install_bin /sbin/mtd - install_bin /sbin/ubi install_bin /sbin/mount_root install_bin /sbin/snapshot install_bin /sbin/snapshot_tool @@ -71,10 +68,11 @@ run_ramfs() { # [...] install_bin /usr/sbin/ubirsvol install_bin /usr/sbin/ubirmvol install_bin /usr/sbin/ubimkvol + install_bin /usr/sbin/partx 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 @@ -99,6 +97,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 @@ -113,18 +118,26 @@ kill_remaining() { # [ ] # 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*|*relayd*) : ;; + + # Killable process + *) + if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then + echo -n "$name " + kill -$sig $pid 2>/dev/null + fi + ;; + esac + fi done echo "" } @@ -173,14 +186,14 @@ get_image() { # [ ] *) cmd="cat";; esac if [ -z "$conc" ]; then - local magic="$(eval $cmd $from 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" + local magic="$(eval $cmd \"$from\" 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" case "$magic" in 1f8b) conc="zcat";; 425a) conc="bzcat";; esac fi - eval "$cmd $from 2>/dev/null ${conc:+| $conc}" + eval "$cmd \"$from\" 2>/dev/null ${conc:+| $conc}" } get_magic_word() { @@ -201,12 +214,16 @@ jffs2_copy_config() { fi } +# Flash firmware to MTD partition +# +# $(1): path to image +# $(2): (optional) pipe command to extract firmware, e.g. dd bs=n skip=m default_do_upgrade() { sync if [ "$SAVE_CONFIG" -eq 1 ]; then - get_image "$1" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}" + get_image "$1" "$2" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}" else - get_image "$1" | mtd write - "${PART_NAME:-image}" + get_image "$1" "$2" | mtd write - "${PART_NAME:-image}" fi }