@@ -17,6 +17,7 @@ extern bool memfd_alloc;
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);
@@ -165,6 +165,7 @@ uint8_t *boot_splash_filedata;
int only_migratable; /* turn it off unless user states otherwise */
bool wakeup_suspend_enabled;
bool memfd_alloc;
+static char **argv_main;
int icount_align_option;
@@ -1294,6 +1295,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;
@@ -1324,6 +1326,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) {
@@ -1570,6 +1577,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();
@@ -1605,6 +1619,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;
@@ -1625,6 +1649,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) {
@@ -2872,6 +2901,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);
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.sistare@oracle.com> --- include/sysemu/sysemu.h | 1 + softmmu/vl.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)