From 100fd332df0407f804f9e214de78ca2d284e7717 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Wed, 7 Oct 2020 13:56:17 +0200 Subject: [PATCH] pmb.qemu.run: add option to set serial to mon:stdio (MR 1980) This makes QEMU trap signals like Ctrl-C and send it to the guest instead of terminating QEMU. To quit QEMU with this option you can use [Ctrl-A] [x] or [Ctrl-A] [c] and type 'quit' at the prompt. This behavior is disabled by default, and can be enabled by setting a new option in the pmbootstrap.cfg (using "pmbootstrap config qemu_redir_stdio true") Co-authored-by: Luca Weiss --- pmb/config/__init__.py | 6 ++++-- pmb/qemu/run.py | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index c3948e9e..2a2fce5c 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -78,7 +78,8 @@ config_keys = ["aports", "work", "boot_size", "extra_space", - "sudo_timer"] + "sudo_timer", + "qemu_redir_stdio"] # Config file/commandline default values # $WORK gets replaced with the actual value for args.work (which may be @@ -120,7 +121,8 @@ defaults = { "work": os.path.expanduser("~") + "/.local/var/pmbootstrap", "boot_size": "256", "extra_space": "0", - "sudo_timer": False + "sudo_timer": False, + "qemu_redir_stdio": False } diff --git a/pmb/qemu/run.py b/pmb/qemu/run.py index d2e9b90f..45a9f167 100644 --- a/pmb/qemu/run.py +++ b/pmb/qemu/run.py @@ -169,7 +169,11 @@ def command_qemu(args, arch, img_path, img_path_2nd=None): command += ["-m", str(args.memory)] - command += ["-serial", "stdio"] + command += ["-serial"] + if args.qemu_redir_stdio: + command += ["mon:stdio"] + else: + command += ["stdio"] command += ["-drive", "file=" + img_path + ",format=raw,if=virtio"] if img_path_2nd: @@ -339,14 +343,24 @@ def run(args): logging.info("* (ssh) ssh -p {port} {user}@localhost".format(**vars(args))) logging.info("* (serial) in this console (stdout/stdin)") + if args.qemu_redir_stdio: + logging.info("NOTE: Ctrl+C is redirected to the VM! To disable this, " + "run: pmbootstrap config qemu_redir_stdio False") + logging.info("NOTE: To quit QEMU with this option you can use " + "Ctrl-A, X.") + # Run QEMU and kill it together with pmbootstrap process = None try: signal.signal(signal.SIGTERM, sigterm_handler) process = pmb.helpers.run.user(args, qemu, output="tui", env=env) except KeyboardInterrupt: - # Don't show a trace when pressing ^C - pass + # In addition to not showing a trace when pressing ^C, let user know + # they can override this behavior: + logging.info("Quitting because Ctrl+C detected.") + logging.info("To override this behavior and have pmbootstrap " + "send Ctrl+C to the VM, run:") + logging.info("$ pmbootstrap config qemu_redir_stdio True") finally: if process: process.terminate()