render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
Mark McLoughlin b20a5c
From: "Daniel P. Berrange" <berrange@redhat.com>
Mark McLoughlin b20a5c
Subject: PATCH: Fix permissions problem starting QEMU
Mark McLoughlin b20a5c
Mark McLoughlin b20a5c
There is a minor bug when running QEMU non-root, and having
Mark McLoughlin b20a5c
capng enabled. libvirt is unable to write the PID file in
Mark McLoughlin b20a5c
/var/run/libvirt/qemu, since its now owned by 'qemu', but
Mark McLoughlin b20a5c
libvirtd has dropped all capabilties at this point. The fix
Mark McLoughlin b20a5c
is to delay dropping capabilities until after the PID file
Mark McLoughlin b20a5c
has been created. We should also be sure to kill the child
Mark McLoughlin b20a5c
if writing the PID file fails
Mark McLoughlin b20a5c
Mark McLoughlin b20a5c
* src/util.c: Don't drop capabilities until after the PID file has
Mark McLoughlin b20a5c
  been written. Kill off child if writing the PID file fails
Mark McLoughlin b20a5c
Mark McLoughlin b20a5c
* src/qemu_driver.c: Remove bogus trailing '/' in state dir
Mark McLoughlin b20a5c
Mark McLoughlin b20a5c
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
Mark McLoughlin b20a5c
index 9fb8506..26897d3 100644
Mark McLoughlin b20a5c
--- a/src/qemu_driver.c
Mark McLoughlin b20a5c
+++ b/src/qemu_driver.c
Mark McLoughlin b20a5c
@@ -468,7 +468,7 @@ qemudStartup(int privileged) {
Mark McLoughlin b20a5c
             goto out_of_memory;
Mark McLoughlin b20a5c
 
Mark McLoughlin b20a5c
         if (virAsprintf(&qemu_driver->stateDir,
Mark McLoughlin b20a5c
-                      "%s/run/libvirt/qemu/", LOCAL_STATE_DIR) == -1)
Mark McLoughlin b20a5c
+                      "%s/run/libvirt/qemu", LOCAL_STATE_DIR) == -1)
Mark McLoughlin b20a5c
             goto out_of_memory;
Mark McLoughlin b20a5c
     } else {
Mark McLoughlin b20a5c
         uid_t uid = geteuid();
Mark McLoughlin b20a5c
diff --git a/src/util.c b/src/util.c
Mark McLoughlin b20a5c
index ee64b28..39aae24 100644
Mark McLoughlin b20a5c
--- a/src/util.c
Mark McLoughlin b20a5c
+++ b/src/util.c
Mark McLoughlin b20a5c
@@ -513,12 +513,6 @@ __virExec(virConnectPtr conn,
Mark McLoughlin b20a5c
         if ((hook)(data) != 0)
Mark McLoughlin b20a5c
             _exit(1);
Mark McLoughlin b20a5c
 
Mark McLoughlin b20a5c
-    /* The hook above may need todo something privileged, so
Mark McLoughlin b20a5c
-     * we delay clearing capabilities until now */
Mark McLoughlin b20a5c
-    if ((flags & VIR_EXEC_CLEAR_CAPS) &&
Mark McLoughlin b20a5c
-        virClearCapabilities() < 0)
Mark McLoughlin b20a5c
-        _exit(1);
Mark McLoughlin b20a5c
-
Mark McLoughlin b20a5c
     /* Daemonize as late as possible, so the parent process can detect
Mark McLoughlin b20a5c
      * the above errors with wait* */
Mark McLoughlin b20a5c
     if (flags & VIR_EXEC_DAEMON) {
Mark McLoughlin b20a5c
@@ -543,6 +537,9 @@ __virExec(virConnectPtr conn,
Mark McLoughlin b20a5c
 
Mark McLoughlin b20a5c
         if (pid > 0) {
Mark McLoughlin b20a5c
             if (pidfile && virFileWritePidPath(pidfile,pid)) {
Mark McLoughlin b20a5c
+                kill(pid, SIGTERM);
Mark McLoughlin b20a5c
+                usleep(500*1000);
Mark McLoughlin b20a5c
+                kill(pid, SIGTERM);
Mark McLoughlin b20a5c
                 virReportSystemError(conn, errno,
Mark McLoughlin b20a5c
                                      "%s", _("could not write pidfile"));
Mark McLoughlin b20a5c
                 _exit(1);
Mark McLoughlin b20a5c
@@ -551,6 +548,12 @@ __virExec(virConnectPtr conn,
Mark McLoughlin b20a5c
         }
Mark McLoughlin b20a5c
     }
Mark McLoughlin b20a5c
 
Mark McLoughlin b20a5c
+    /* The steps above may need todo something privileged, so
Mark McLoughlin b20a5c
+     * we delay clearing capabilities until the last minute */
Mark McLoughlin b20a5c
+    if ((flags & VIR_EXEC_CLEAR_CAPS) &&
Mark McLoughlin b20a5c
+        virClearCapabilities() < 0)
Mark McLoughlin b20a5c
+        _exit(1);
Mark McLoughlin b20a5c
+
Mark McLoughlin b20a5c
     if (envp)
Mark McLoughlin b20a5c
         execve(argv[0], (char **) argv, (char**)envp);
Mark McLoughlin b20a5c
     else
Mark McLoughlin b20a5c
Mark McLoughlin b20a5c