diff --git a/package/base-files/files/lib/preinit/10_indicate_failsafe b/package/base-files/files/lib/preinit/10_indicate_failsafe index 7bf5e029e42..8c950bff74d 100644 --- a/package/base-files/files/lib/preinit/10_indicate_failsafe +++ b/package/base-files/files/lib/preinit/10_indicate_failsafe @@ -9,9 +9,14 @@ indicate_failsafe_led () { indicate_failsafe() { [ "$pi_preinit_no_failsafe" = "y" ] && return - echo "- failsafe -" + local consoles="$(cat /sys/class/tty/console/active)" + [ -n "$consoles" ] || consoles=console + for console in $consoles; do + [ -c "/dev/$console" ] && echo "- failsafe -" >"/dev/$console" + done preinit_net_echo "Entering Failsafe!\n" indicate_failsafe_led + echo OpenWrt-failsafe > /proc/sys/kernel/hostname } boot_hook_add failsafe indicate_failsafe diff --git a/package/base-files/files/lib/preinit/30_failsafe_wait b/package/base-files/files/lib/preinit/30_failsafe_wait index 9ab2e8bd4d8..c792089ece1 100644 --- a/package/base-files/files/lib/preinit/30_failsafe_wait +++ b/package/base-files/files/lib/preinit/30_failsafe_wait @@ -40,7 +40,7 @@ fs_wait_for_key () { rm -f $keypress_wait } & - local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')" + local consoles="$(cat /sys/class/tty/console/active)" [ -n "$consoles" ] || consoles=console for console in $consoles; do [ -c "/dev/$console" ] || continue @@ -78,6 +78,9 @@ fs_wait_for_key () { keypressed=1 [ "$(cat $keypress_true)" = "true" ] && keypressed=0 + trap - INT + trap - USR1 + rm -f $keypress_true rm -f $keypress_wait rm -f $keypress_sec diff --git a/package/base-files/files/lib/preinit/99_10_failsafe_login b/package/base-files/files/lib/preinit/99_10_failsafe_login index 6f4af3f28b5..f72a35ed531 100644 --- a/package/base-files/files/lib/preinit/99_10_failsafe_login +++ b/package/base-files/files/lib/preinit/99_10_failsafe_login @@ -2,14 +2,22 @@ # Copyright (C) 2010 Vertical Communications failsafe_shell() { - local consoles="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | sed -e 's/^console=//' -e 's/,.*//')" + local consoles="$(cat /sys/class/tty/console/active)" [ -n "$consoles" ] || consoles=console for console in $consoles; do - [ -c "/dev/$console" ] && while true; do - ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console" - sleep 1 - done & + case "$console" in + console|tty[0-9]*) + term=${TERM:-linux} + ;; + *) + term=vt102 + ;; + esac + # Running asynchronously via the shell's & would ignore SIGINT, + # breaking ^C. Use start-stop-daemon instead. + [ -c "/dev/$console" ] && start-stop-daemon -Sb -p /dev/null -- env -i ash -c "while true; do setsid -c env -i USER=root LOGNAME=root SHELL=/bin/ash TERM="$term" ash --login <\"/dev/$console\" >\"/dev/$console\" 2>\"/dev/$console\"; sleep 1; done" done + } boot_hook_add failsafe failsafe_shell diff --git a/package/base-files/files/usr/libexec/login.sh b/package/base-files/files/usr/libexec/login.sh index 1fff39c6a06..e2f898e850c 100755 --- a/package/base-files/files/usr/libexec/login.sh +++ b/package/base-files/files/usr/libexec/login.sh @@ -1,5 +1,17 @@ #!/bin/sh -[ "$(uci -q get system.@system[0].ttylogin)" = 1 ] || exec /bin/ash --login +[ -t 0 ] && { + tty_dev=$(readlink /proc/self/fd/0) + case "$tty_dev" in + /dev/console|/dev/tty[0-9]*) + export TERM=${TERM:-linux} + ;; + /dev/*) + export TERM=vt102 + ;; + esac +} + +[ "$(uci -q get system.@system[0].ttylogin)" = 1 ] || exec /bin/login -f root exec /bin/login diff --git a/package/utils/busybox/Config-defaults.in b/package/utils/busybox/Config-defaults.in index 515bea3d1d7..f88f395e2cb 100644 --- a/package/utils/busybox/Config-defaults.in +++ b/package/utils/busybox/Config-defaults.in @@ -1801,7 +1801,7 @@ config BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITY_NAMES default n config BUSYBOX_DEFAULT_SETSID bool - default n + default y config BUSYBOX_DEFAULT_SWAPON bool default y