[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#512679: [PATCH initramfs-tools] scripts/functions: Connect panic shell to normal tty device



Control: tag -1 patch pending

I worked out how to do this without setsid -c.

Ben.
---
Currently the panic shell's controlling tty is /dev/console which is
not fully functional - the shell can't provide job control and more
can't work out the screen size for paging.

Fix this by reading /proc/consoles to find out the underlying tty
device and then connecting the shell to it directly with the aid of
setsid.

Closes: #512679
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 scripts/functions | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/scripts/functions b/scripts/functions
index 531d1bd..67ce319 100644
--- a/scripts/functions
+++ b/scripts/functions
@@ -33,6 +33,8 @@ log_end_msg()
 
 panic()
 {
+	local console rest
+
 	if command -v chvt >/dev/null 2>&1; then
 		chvt 1
 	fi
@@ -48,7 +50,20 @@ panic()
 
 	run_scripts /scripts/panic
 
-	REASON="$@" PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1
+	# Try to use setsid, which will enable job control in the shell
+	# and paging in more
+	if command -v setsid >/dev/null 2>&1; then
+		read console rest </proc/consoles
+		if [ "${console}" = "tty0" ]; then
+			# Need to choose a specific VT
+			console="tty1"
+		fi
+		# We don't have 'setsid -c' so we need to setsid, open
+		# the tty, and finally exec an interactive shell
+		REASON="$@" PS1='(initramfs) ' setsid sh -c "exec sh -i <>/dev/${console} 1>&0 2>&1"
+	else
+		REASON="$@" PS1='(initramfs) ' sh -i </dev/console >/dev/console 2>&1
+	fi
 }
 
 maybe_break()

Attachment: signature.asc
Description: Digital signature


Reply to: