summaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib/preinit/99_10_failsafe_login
blob: f72a35ed5311cc745decfa329d77c94482acb388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Copyright (C) 2006-2015 OpenWrt.org
# Copyright (C) 2010 Vertical Communications

failsafe_shell() {
	local consoles="$(cat /sys/class/tty/console/active)"
	[ -n "$consoles" ] || consoles=console
	for console in $consoles; do
		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