]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: don't attempt to acquire logind inhibitor if not requested
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 8 Jan 2025 17:37:03 +0000 (17:37 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 9 Jan 2025 09:24:20 +0000 (09:24 +0000)
When VIR_INHIBITOR_WHAT_NONE is passed to virInhibitorNew, it is
an indication that daemon shutdown should be inhibited, but no
OS level inhibitors acquired. This is done by the virtnetworkd
daemon, for example, to prevent shutdown while running virtual
machines are present, without blocking / delaying OS shutdown.

Unfortunately the code forgot to skip the DBus call in this case,
resulting in errors being logged.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virinhibitor.c

index 647bdc9fbbe5b20d7c4ebac3a0a0646d3b752367..a95021de5ab92f850f9baa5b32929f23c59a3757 100644 (file)
@@ -152,7 +152,7 @@ virInhibitor *virInhibitorNew(virInhibitorWhat what,
     virInhibitor *inhibitor = g_new0(virInhibitor, 1);
 
     inhibitor->fd = -1;
-    inhibitor->what = virInhibitorWhatFormat(what);
+    inhibitor->what = what ? virInhibitorWhatFormat(what) : NULL;
     inhibitor->who = g_strdup(who);
     inhibitor->why = g_strdup(why);
     inhibitor->mode = virInhibitorModeTypeToString(mode);
@@ -171,7 +171,8 @@ void virInhibitorHold(virInhibitor *inhibitor)
             inhibitor->action(true, inhibitor->actionData);
         }
 #ifdef G_OS_UNIX
-        if (virInhibitorAcquire(
+        if (inhibitor->what &&
+            virInhibitorAcquire(
                 inhibitor->what, inhibitor->who, inhibitor->why,
                 inhibitor->mode, &inhibitor->fd) < 0) {
             VIR_ERROR(_("Failed to acquire inhibitor: %1$s"),