From c0e47ef3eb531ea650db378a06e4a63bab5dbd77 Mon Sep 17 00:00:00 2001 From: Mike Baker Date: Mon, 30 Oct 2006 09:42:29 +0000 Subject: [PATCH] rewrite failsafe mechaism SVN-Revision: 5338 --- .../base-files/default/etc/functions.sh | 7 ++-- .../package/base-files/default/etc/init.d/rcS | 3 -- .../package/base-files/default/etc/preinit | 41 ++++++++----------- .../base-files/default/sbin/hotplug.failsafe | 15 ++++++- .../base-files/default/sbin/mount_root | 3 -- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/openwrt/package/base-files/default/etc/functions.sh b/openwrt/package/base-files/default/etc/functions.sh index 60ead7f13a..fd0bc64711 100755 --- a/openwrt/package/base-files/default/etc/functions.sh +++ b/openwrt/package/base-files/default/etc/functions.sh @@ -185,10 +185,9 @@ set_state() { set_led power 0 ;; failsafe) - set_led diag 0 && led=diag - set_led power 1 && led=power - set_led dmz 0 && led=dmz - while :; do { set_led "$led" $(((X=(X+1)%8)%2)); sleep $((X==0)); } done & + set_led diag f + set_led power f + set_led dmz f ;; done) set_led dmz 0 diff --git a/openwrt/package/base-files/default/etc/init.d/rcS b/openwrt/package/base-files/default/etc/init.d/rcS index 9e3285915d..d93c81224c 100755 --- a/openwrt/package/base-files/default/etc/init.d/rcS +++ b/openwrt/package/base-files/default/etc/init.d/rcS @@ -1,12 +1,9 @@ #!/bin/sh -${FAILSAFE:+exit} - syslog_ip=$(nvram get log_ipaddr) eval $(ipcalc "$syslog_ip") [ "$syslog_ip" = "$IP" ] || syslog_ip="" syslogd -C 16 ${syslog_ip:+-L -R $syslog_ip} klogd -#${FAILSAFE:+telnetd -l /bin/login; ifup lan; exit} for i in /etc/init.d/S*; do $i start 2>&1 done | logger -s -p 6 -t '' & diff --git a/openwrt/package/base-files/default/etc/preinit b/openwrt/package/base-files/default/etc/preinit index 029f7c2b71..a89ff31c6f 100755 --- a/openwrt/package/base-files/default/etc/preinit +++ b/openwrt/package/base-files/default/etc/preinit @@ -3,7 +3,11 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin mount none /proc -t proc +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2) /proc/sys/kernel/hotplug set_state preinit ifname=eth0 @@ -30,33 +34,22 @@ insmod switch-robo || insmod switch-adm || rmmod switch-core } ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up -netmsg 192.168.1.0 "(dummy message)" # b44 eats the first packet netmsg 192.168.1.255 "Press reset now, to enter Failsafe!" -echo /sbin/hotplug.failsafe > /proc/sys/kernel/hotplug -if sleep 2; then - ifconfig $ifname 0.0.0.0 - - # revert to the boot loader's vlan config - # required for at least WRT54G v1.1 - [ -d /proc/switch/eth0 ] && { - echo "$v0p" > /proc/switch/eth0/vlan/0/ports - echo "$v1p" > /proc/switch/eth0/vlan/1/ports - echo "$v2p" > /proc/switch/eth0/vlan/2/ports - } -else - # sleep was interrupted by a hotplug event - enter failsafe mode - set_state failsafe - export FAILSAFE=true - [ "$(nvram get boot_wait)" != "on" ] && { - nvram set boot_wait=on - nvram commit - } - netmsg 192.168.1.255 "Entering Failsafe!" - telnetd -l /bin/login <> /dev/null 2>&1 -fi +sleep 2 +lock -w /tmp/.failsafe echo /sbin/hotplug > /proc/sys/kernel/hotplug -mount_root ${FAILSAFE:+failsafe} +ifconfig $ifname 0.0.0.0 down + +# revert to the boot loader's vlan config +# required for at least WRT54G v1.1 +[ -d /proc/switch/eth0 ] && { + echo "$v0p" > /proc/switch/eth0/vlan/0/ports + echo "$v1p" > /proc/switch/eth0/vlan/1/ports + echo "$v2p" > /proc/switch/eth0/vlan/2/ports +} + +mount_root exec /sbin/init diff --git a/openwrt/package/base-files/default/sbin/hotplug.failsafe b/openwrt/package/base-files/default/sbin/hotplug.failsafe index f2091e0a48..867e766263 100755 --- a/openwrt/package/base-files/default/sbin/hotplug.failsafe +++ b/openwrt/package/base-files/default/sbin/hotplug.failsafe @@ -1,3 +1,14 @@ #!/bin/sh -# trigger for failsafe mode -[ "$1" = "button" ] && killall sleep +[ "$1" = "button" -a "$ACTION" = "pressed" ] && { + lock /tmp/.failsafe + + . /etc/functions.sh + set_state failsafe + [ "$(nvram get boot_wait)" != "on" ] && { + nvram set boot_wait=on + nvram commit + } + + netmsg 192.168.1.255 "Entering Failsafe!" + telnetd -l /bin/login <> /dev/null 2>&1 +} diff --git a/openwrt/package/base-files/default/sbin/mount_root b/openwrt/package/base-files/default/sbin/mount_root index 6c2ef6ed58..9d336863c9 100755 --- a/openwrt/package/base-files/default/sbin/mount_root +++ b/openwrt/package/base-files/default/sbin/mount_root @@ -5,9 +5,6 @@ is_dirty() { return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"') } -size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)&- -- 2.30.2