summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/qemu-fix-agent-paths.patch
blob: 91572fb664c8159d1e6971e115e3bcf7a7d49394 (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
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
Allow a QEMU host to set the time and shutdown Guix guests.  Styled
after the patch from the Nix package:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/virtualization/qemu/fix-qemu-ga.patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 6e3c15f539..eaef900b6e 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -216,6 +216,7 @@ out:
 void qmp_guest_shutdown(const char *mode, Error **errp)
 {
     const char *shutdown_flag;
+    const char *command;
     Error *local_err = NULL;
 
 #ifdef CONFIG_SOLARIS
@@ -235,16 +236,24 @@ void qmp_guest_shutdown(const char *mode, Error **errp)
     slog("guest-shutdown called, mode: %s", mode);
     if (!mode || strcmp(mode, "powerdown") == 0) {
         shutdown_flag = powerdown_flag;
+        command = "shutdown";
     } else if (strcmp(mode, "halt") == 0) {
         shutdown_flag = halt_flag;
+        command = "halt";
     } else if (strcmp(mode, "reboot") == 0) {
         shutdown_flag = reboot_flag;
+        command = "reboot";
     } else {
         error_setg(errp,
                    "mode is invalid (valid values are: halt|powerdown|reboot");
         return;
     }
 
+    /* Try Guix’s shutdown/halt/reboot first. */
+    char *path = g_strdup_printf("/run/current-system/profile/sbin/%s", command);
+    execl(path, command, (char *) NULL);
+    g_free(path);
+
     const char *argv[] = {"/sbin/shutdown",
 #ifdef CONFIG_SOLARIS
                           shutdown_flag, "-g0", "-y",
@@ -269,7 +278,7 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
     int ret;
     Error *local_err = NULL;
     struct timeval tv;
-    const char *argv[] = {"/sbin/hwclock", has_time ? "-w" : "-s", NULL};
+    const char *argv[] = {"/run/current-system/profile/sbin/hwclock", has_time ? "-w" : "-s", NULL};
 
     /* If user has passed a time, validate and set it. */
     if (has_time) {
@@ -302,6 +311,11 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
      * hardware clock (RTC). */
     ga_run_command(argv, NULL, "set hardware clock to system time",
                    &local_err);
+    if (local_err) {
+        argv[0] = "/sbin/hwclock";
+        ga_run_command(argv, NULL, "set hardware clock to system time",
+                       &local_err);
+    }
     if (local_err) {
         error_propagate(errp, local_err);
         return;