[PATCH] util: don't attempt to acquire logind inhibitor if not requested

Daniel P. Berrangé posted 1 patch 11 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20250108191315.1031618-1-berrange@redhat.com
src/util/virinhibitor.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] util: don't attempt to acquire logind inhibitor if not requested
Posted by Daniel P. Berrangé 11 months, 2 weeks ago
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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/util/virinhibitor.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virinhibitor.c b/src/util/virinhibitor.c
index 647bdc9fbb..a95021de5a 100644
--- a/src/util/virinhibitor.c
+++ b/src/util/virinhibitor.c
@@ -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"),
-- 
2.47.1
Re: [PATCH] util: don't attempt to acquire logind inhibitor if not requested
Posted by Laine Stump 11 months, 2 weeks ago
On 1/8/25 2:13 PM, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Reviewed-by: Laine Stump <laine@redhat.com>

> ---
>   src/util/virinhibitor.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/virinhibitor.c b/src/util/virinhibitor.c
> index 647bdc9fbb..a95021de5a 100644
> --- a/src/util/virinhibitor.c
> +++ b/src/util/virinhibitor.c
> @@ -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"),