Add a qemu_exec_requested() hook that causes the main loop to exit and re-exec qemu using the same initial arguments. If /usr/bin/qemu-exec exists, exec that instead. This is an optional site-specific trampoline that may alter the environment before exec'ing the qemu binary.
Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- include/sysemu/sysemu.h | 1 + softmmu/vl.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 5360da5..4dfc4ca 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -15,6 +15,7 @@ extern QemuUUID qemu_uuid; extern bool qemu_uuid_set; void qemu_add_data_dir(const char *path); +void qemu_system_exec_request(void); void qemu_add_exit_notifier(Notifier *notify); void qemu_remove_exit_notifier(Notifier *notify); diff --git a/softmmu/vl.c b/softmmu/vl.c index 7016e39..72f0e08 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -116,6 +116,7 @@ #define MAX_VIRTIO_CONSOLES 1 +static char **argv_main; static const char *data_dir[16]; static int data_dir_idx; const char *bios_name = NULL; @@ -1296,6 +1297,7 @@ static ShutdownCause reset_requested; static ShutdownCause shutdown_requested; static int shutdown_signal; static pid_t shutdown_pid; +static int exec_requested; static int powerdown_requested; static int debug_requested; static int suspend_requested; @@ -1326,6 +1328,11 @@ static int qemu_shutdown_requested(void) return atomic_xchg(&shutdown_requested, SHUTDOWN_CAUSE_NONE); } +static int qemu_exec_requested(void) +{ + return atomic_xchg(&exec_requested, 0); +} + static void qemu_kill_report(void) { if (!qtest_driver() && shutdown_signal) { @@ -1582,6 +1589,13 @@ void qemu_system_shutdown_request(ShutdownCause reason) qemu_notify_event(); } +void qemu_system_exec_request(void) +{ + shutdown_requested = 1; + exec_requested = 1; + qemu_notify_event(); +} + static void qemu_system_powerdown(void) { qapi_event_send_powerdown(); @@ -1617,6 +1631,16 @@ void qemu_system_debug_request(void) qemu_notify_event(); } +static void qemu_exec(void) +{ + const char *helper = "/usr/bin/qemu-exec"; + const char *bin = !access(helper, X_OK) ? helper : argv_main[0]; + + execvp(bin, argv_main); + error_report("execvp failed, errno %d.", errno); + exit(1); +} + static bool main_loop_should_exit(void) { RunState r; @@ -1637,6 +1661,11 @@ static bool main_loop_should_exit(void) } request = qemu_shutdown_requested(); if (request) { + + if (qemu_exec_requested()) { + qemu_exec(); + /* not reached */ + } qemu_kill_report(); qemu_system_shutdown(request); if (no_shutdown) { @@ -2891,6 +2920,7 @@ void qemu_init(int argc, char **argv, char **envp) os_set_line_buffering(); + argv_main = argv; error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); -- 1.8.3.1