diff options
author | Timotej Lazar <timotej.lazar@araneo.si> | 2021-10-23 12:03:18 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2021-10-30 19:16:23 +0200 |
commit | 142344b6efa42e1a4d57a4bdf14dfb3ca1cba25a (patch) | |
tree | 5d73df026c0e08e2c1d2e0a898e12c6b3bb29d50 /gnu/packages/patches | |
parent | f8d3c98162910b3d715c93f73ae9e7d278de6840 (diff) |
gnu: qemu: Add Guix support to QEMU guest agent.
QEMU guest agent hardcodes paths to /sbin/hwclock and /sbin/shutdown. Patch
the source to try binaries under /run/current-system/profile/sbin first.
* gnu/packages/patches/qemu-fix-agent-paths.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register the patch.
* gnu/packages/virtualization.scm (qemu)[origin]: Apply it.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/packages/patches')
-rw-r--r-- | gnu/packages/patches/qemu-fix-agent-paths.patch | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gnu/packages/patches/qemu-fix-agent-paths.patch b/gnu/packages/patches/qemu-fix-agent-paths.patch new file mode 100644 index 0000000000..bae62fadbf --- /dev/null +++ b/gnu/packages/patches/qemu-fix-agent-paths.patch @@ -0,0 +1,66 @@ +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 75dbaab..b416b03 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 *command; + Error *local_err = NULL; + pid_t pid; + int status; +@@ -91,10 +92,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 = "-P"; ++ command = "shutdown"; + } else if (strcmp(mode, "halt") == 0) { + shutdown_flag = "-H"; ++ command = "halt"; + } else if (strcmp(mode, "reboot") == 0) { + shutdown_flag = "-r"; ++ command = "reboot"; + } else { + error_setg(errp, + "mode is invalid (valid values are: halt|powerdown|reboot"); +@@ -109,6 +113,11 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) + reopen_fd_to_null(1); + reopen_fd_to_null(2); + ++ /* try Guix’s shutdown/halt/reboot first */ ++ char *path = g_strdup_printf("/run/current-system/profile/sbin/%s", command); ++ execle(path, command, (char *)NULL, environ); ++ g_free(path); ++ + execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL, environ); + _exit(EXIT_FAILURE); +@@ -158,10 +167,12 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) + Error *local_err = NULL; + struct timeval tv; + static const char hwclock_path[] = "/sbin/hwclock"; ++ static const char hwclock_path_guix[] = "/run/current-system/profile/sbin/hwclock"; + static int hwclock_available = -1; + + if (hwclock_available < 0) { +- hwclock_available = (access(hwclock_path, X_OK) == 0); ++ hwclock_available = (access(hwclock_path_guix, X_OK) == 0) || ++ (access(hwclock_path, X_OK) == 0); + } + + if (!hwclock_available) { +@@ -207,6 +218,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) + + /* Use '/sbin/hwclock -w' to set RTC from the system time, + * or '/sbin/hwclock -s' to set the system time from RTC. */ ++ execle(hwclock_path_guix, "hwclock", has_time ? "-w" : "-s", ++ NULL, environ); + execle(hwclock_path, "hwclock", has_time ? "-w" : "-s", + NULL, environ); + _exit(EXIT_FAILURE); |