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 <luca@z3ntu.xyz>
This commit is contained in:
parent
dfe8129640
commit
100fd332df
|
@ -78,7 +78,8 @@ config_keys = ["aports",
|
||||||
"work",
|
"work",
|
||||||
"boot_size",
|
"boot_size",
|
||||||
"extra_space",
|
"extra_space",
|
||||||
"sudo_timer"]
|
"sudo_timer",
|
||||||
|
"qemu_redir_stdio"]
|
||||||
|
|
||||||
# Config file/commandline default values
|
# Config file/commandline default values
|
||||||
# $WORK gets replaced with the actual value for args.work (which may be
|
# $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",
|
"work": os.path.expanduser("~") + "/.local/var/pmbootstrap",
|
||||||
"boot_size": "256",
|
"boot_size": "256",
|
||||||
"extra_space": "0",
|
"extra_space": "0",
|
||||||
"sudo_timer": False
|
"sudo_timer": False,
|
||||||
|
"qemu_redir_stdio": False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,11 @@ def command_qemu(args, arch, img_path, img_path_2nd=None):
|
||||||
|
|
||||||
command += ["-m", str(args.memory)]
|
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"]
|
command += ["-drive", "file=" + img_path + ",format=raw,if=virtio"]
|
||||||
if img_path_2nd:
|
if img_path_2nd:
|
||||||
|
@ -339,14 +343,24 @@ def run(args):
|
||||||
logging.info("* (ssh) ssh -p {port} {user}@localhost".format(**vars(args)))
|
logging.info("* (ssh) ssh -p {port} {user}@localhost".format(**vars(args)))
|
||||||
logging.info("* (serial) in this console (stdout/stdin)")
|
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
|
# Run QEMU and kill it together with pmbootstrap
|
||||||
process = None
|
process = None
|
||||||
try:
|
try:
|
||||||
signal.signal(signal.SIGTERM, sigterm_handler)
|
signal.signal(signal.SIGTERM, sigterm_handler)
|
||||||
process = pmb.helpers.run.user(args, qemu, output="tui", env=env)
|
process = pmb.helpers.run.user(args, qemu, output="tui", env=env)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# Don't show a trace when pressing ^C
|
# In addition to not showing a trace when pressing ^C, let user know
|
||||||
pass
|
# 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:
|
finally:
|
||||||
if process:
|
if process:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
|
|
Loading…
Reference in New Issue