summary refs log tree commit diff stats
path: root/gitlab/issues/target_missing/host_missing/accel_missing/2589.toml
blob: 3dd816bc9d0d8445becce35be517a57999088db1 (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
id = 2589
title = "Support guest shutdown of Alpine Linux in guest agent"
state = "opened"
created_at = "2024-09-25T10:04:34.136Z"
closed_at = "n/a"
labels = ["Guest Agent", "kind::Feature Request"]
url = "https://gitlab.com/qemu-project/qemu/-/issues/2589"
host-os = "n/a"
host-arch = "n/a"
qemu-version = "all"
guest-os = "Alpine Linux"
guest-arch = "all"
description = """The qemu-guest-agent's shutdown calls `/sbin/shutdown` with the apropriate flags to shut down a posix system. On Alpine Linux, which is based on busybox, there is no `/sbin/shutdown`, instead there are `/sbin/poweroff`, `/sbin/halt` and `/sbin/reboot`. We have used a downstream patch for years that will exec those as a fallback in case execing `/sbin/shutdown` fails.

With qemu 9.2 this patch no longer applies and it is probably time to solve this properly in upstream qemu.

The question is how?

Some options:

- Set the powerdown, halt and reboot commands via build time configure option
- Add a fallback if the `execlp` fails (similar to what downstream Alpine's patch does now). We could for example give `ga_run_command` a `const char **argv[]`, and try `execvp` all of them before erroring out.
- Test the existence of `/sbin/shutdown` before calling `ga_run_command`.
- Do nothing. Let downstream Alpine Linux handle it."""
reproduce = """1. Build qemu-guest-agent for Alpine Linux
2. boot a Alpine linux VM and install the qemu-guest-agent
3. Try shutdown the VM via qmp command."""
additional = """The patch that we previously used that no longer applies:
```diff
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) {
```"""