From 8c73e9aa4e09659bf6770a0bb85f8126a97f42d1 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 3 Mar 2017 09:56:03 +0000 Subject: [PATCH] appliance: Fix job control in virt-rescue. See comment and link to busybox FAQ for explanation. --- appliance/init | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/appliance/init b/appliance/init index 8be27a295..bb8b70949 100755 --- a/appliance/init +++ b/appliance/init @@ -177,6 +177,10 @@ if ! test "$guestfs_rescue" = 1; then else # Run virt-rescue shell. + # Get name of the serial port, from console= passed by libguestfs. + guestfs_serial=$(grep -Eo 'console=[^[:space:]]+' /proc/cmdline | + sed s/console=//) + # Remove LD_PRELOAD=libSegFault set above. unset LD_PRELOAD @@ -185,6 +189,16 @@ else echo "PS1='> '" >> $HOME/.bashrc echo "export TERM PS1" >> $HOME/.bashrc + # The shell is opened by default on /dev/console, which (on Linux) + # is not a controlling terminal, causing job control to fail. For + # how we work around this, see: + # https://busybox.net/FAQ.html#job_control + run_bash_with_ctty () + { + setsid bash -c \ + "exec bash /dev/$guestfs_serial 2>&1" + } + echo echo "------------------------------------------------------------" echo @@ -194,7 +208,7 @@ else echo "You have to mount the guest's partitions under /sysroot" echo "before you can examine them." echo - bash -i + run_bash_with_ctty echo echo "virt-rescue: Syncing the disk now before exiting ..." echo