emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#51347: closed ([PATCH] gnu: qemu: Add Guix support to QEMU guest age


From: GNU bug Tracking System
Subject: bug#51347: closed ([PATCH] gnu: qemu: Add Guix support to QEMU guest agent.)
Date: Sat, 30 Oct 2021 17:23:02 +0000

Your message dated Sat, 30 Oct 2021 19:22:22 +0200
with message-id <87ee82sa0h.fsf@gnu.org>
and subject line Re: bug#51347: [PATCH] gnu: qemu: Add Guix support to QEMU 
guest agent.
has caused the debbugs.gnu.org bug report #51347,
regarding [PATCH] gnu: qemu: Add Guix support to QEMU guest agent.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
51347: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=51347
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: [PATCH] gnu: qemu: Add Guix support to QEMU guest agent. Date: Sat, 23 Oct 2021 12:03:18 +0200
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.
---
This allows 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

Thanks!

 gnu/local.mk                                  |  1 +
 .../patches/qemu-fix-agent-paths.patch        | 61 +++++++++++++++++++
 gnu/packages/virtualization.scm               |  3 +-
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/qemu-fix-agent-paths.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index d432829e2d..9a900e7c30 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1707,6 +1707,7 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/qemu-CVE-2021-20203.patch               \
   %D%/packages/patches/qemu-glibc-2.27.patch                   \
   %D%/packages/patches/qemu-glibc-2.30.patch                   \
+  %D%/packages/patches/qemu-fix-agent-paths.patch              \
   %D%/packages/patches/qpdfview-qt515-compat.patch             \
   %D%/packages/patches/qrcodegen-cpp-make-install.patch                \
   %D%/packages/patches/qt4-ldflags.patch                       \
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..22cf883a8d
--- /dev/null
+++ b/gnu/packages/patches/qemu-fix-agent-paths.patch
@@ -0,0 +1,61 @@
+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);
diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm
index fb6e8ebfa3..fd778e21a4 100644
--- a/gnu/packages/virtualization.scm
+++ b/gnu/packages/virtualization.scm
@@ -159,7 +159,8 @@ (define-public qemu
         (base32
          "15iw7982g6vc4jy1l9kk1z9sl5bm1bdbwr74y7nvwjs1nffhig7f"))
        (patches (search-patches "qemu-CVE-2021-20203.patch"
-                                "qemu-build-info-manual.patch"))
+                                "qemu-build-info-manual.patch"
+                                "qemu-fix-agent-paths.patch"))
        (modules '((guix build utils)))
        (snippet
         '(begin
-- 
2.33.1




--- End Message ---
--- Begin Message --- Subject: Re: bug#51347: [PATCH] gnu: qemu: Add Guix support to QEMU guest agent. Date: Sat, 30 Oct 2021 19:22:22 +0200 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Hi Timotej,

Timotej Lazar <timotej.lazar@araneo.si> skribis:

> 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.
> ---
> This allows 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

Neat!  I added this bit as a comment at the top of the patch and
committed.

Thanks!

Ludo’.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]