[Libguestfs] [PATCH v3 3/7] appliance: Fix job control in virt-rescue.

Richard W.M. Jones rjones at redhat.com
Sat Mar 4 15:11:02 UTC 2017


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 8be27a2..bb8b709 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='><rescue> '" >> $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 >/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
-- 
2.9.3




More information about the Libguestfs mailing list