diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 954efed01..61427652c 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -84,6 +84,7 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp) void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) { const char *shutdown_flag; + const char *fallback_cmd = NULL; Error *local_err = NULL; pid_t pid; int status; @@ -101,10 +102,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) slog("guest-shutdown called, mode: %s", mode); if (!has_mode || strcmp(mode, "powerdown") == 0) { shutdown_flag = powerdown_flag; + fallback_cmd = "/sbin/poweroff"; } else if (strcmp(mode, "halt") == 0) { shutdown_flag = halt_flag; + fallback_cmd = "/sbin/halt"; } else if (strcmp(mode, "reboot") == 0) { shutdown_flag = reboot_flag; + fallback_cmd = "/sbin/reboot"; } else { error_setg(errp, "mode is invalid (valid values are: halt|powerdown|reboot"); @@ -125,6 +129,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) #else execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", "hypervisor initiated shutdown", (char *)NULL); + execle(fallback_cmd, fallback_cmd, (char*)NULL, environ); #endif _exit(EXIT_FAILURE); } else if (pid < 0) {