Skip to contentSkip to conversation

kvm tools: Set active console before running /bin/sh

PATCH Superseded Sasha Levin 1 participant 1 message Sep 27, 2011 KVM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Set active console before running /bin/sh

This patch sets active console to the serial console before running the shell. Doing so fixes two issues:

* Fix job control.

* Set all env vars.

The user visible issues are less warnings (no more of this:
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell)

A working 'top', and a working ctrl-c.

---
 tools/kvm/guest/init.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
tools/kvm/guest/init.c +6 -0
index 837acfb..b55cd30 100644
@@ -30,6 +30,12 @@ int main(int argc, char *argv[])
 
 	do_mounts();
 
+        /* get session leader */
+        setsid();
+
+        /* set controlling terminal */
+        ioctl (0, TIOCSCTTY, 1);
+
 	puts("Starting '/bin/sh'...");
 
 	run_process("/bin/sh");
Signature · 1 line
1.7.6.1