summaryrefslogtreecommitdiff
path: root/repo/qemu/guest-agent-shutdown.patch
blob: ddf3fdf00876852e97ff4b75407f656eb47f22bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--- a/qga/commands-posix.c	2021-04-30 14:07:31.202337082 +0000
+++ b/qga/commands-posix.c	2021-04-30 14:10:05.253272361 +0000
@@ -84,6 +84,7 @@ static void ga_wait_child(pid_t pid, int
 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;
@@ -91,10 +92,13 @@ void qmp_guest_shutdown(bool has_mode, c
     slog("guest-shutdown called, mode: %s", mode);
     if (!has_mode || strcmp(mode, "powerdown") == 0) {
         shutdown_flag = "-P";
+        fallback_cmd = "/sbin/poweroff";
     } else if (strcmp(mode, "halt") == 0) {
         shutdown_flag = "-H";
+        fallback_cmd = "/sbin/halt";
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag = "-r";
+        fallback_cmd = "/sbin/reboot";
     } else {
         error_setg(errp,
                    "mode is invalid (valid values are: halt|powerdown|reboot");
@@ -111,6 +115,7 @@ void qmp_guest_shutdown(bool has_mode, c
 
         execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
                "hypervisor initiated shutdown", (char *)NULL, environ);
+        execle(fallback_cmd, fallback_cmd, (char*)NULL, environ);
         _exit(EXIT_FAILURE);
     } else if (pid < 0) {
         error_setg_errno(errp, errno, "failed to create child process");