Re: [PATCH 2/8] systemd: don't report an error if the guest is already terminated

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

 



On 16.01.2015 18:36, Daniel P. Berrange wrote:
> In many cases where we invoke virSystemdTerminateMachine the
> process(es) will have already gone away on their own accord.
> In these cases we log an error message that the machine does
> not exist. We should catch this particular error and simply
> ignore it, so we don't pollute the logs.
> ---
>  src/util/virsystemd.c | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
> index 3eea5c2..29a2e63 100644
> --- a/src/util/virsystemd.c
> +++ b/src/util/virsystemd.c
> @@ -340,18 +340,22 @@ int virSystemdTerminateMachine(const char *name,
>      int ret;
>      DBusConnection *conn;
>      char *machinename = NULL;
> +    DBusError error;
> +
> +    dbus_error_init(&error);

This will suffer the same issue we already have in the code in
virSystemdCreateMachine if libvirt is built without DBUS.

>  
>      ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
>      if (ret < 0)
> -        return ret;
> +        goto cleanup;
>  
>      if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
> -        return ret;
> +        goto cleanup;
> +
> +    ret = -1;
>  
>      if (!(conn = virDBusGetSystemBus()))
> -        return -1;
> +        goto cleanup;
>  
> -    ret = -1;
>      if (!(machinename = virSystemdMakeMachineName(name, drivername, privileged)))
>          goto cleanup;
>  
> @@ -368,7 +372,7 @@ int virSystemdTerminateMachine(const char *name,
>      VIR_DEBUG("Attempting to terminate machine via systemd");
>      if (virDBusCallMethod(conn,
>                            NULL,
> -                          NULL,
> +                          &error,
>                            "org.freedesktop.machine1",
>                            "/org/freedesktop/machine1",
>                            "org.freedesktop.machine1.Manager",
> @@ -377,9 +381,20 @@ int virSystemdTerminateMachine(const char *name,
>                            machinename) < 0)
>          goto cleanup;
>  
> +    if (dbus_error_is_set(&error) &&
> +        !STREQ_NULLABLE("org.freedesktop.machine1.NoSuchMachine",
> +                        error.name)) {
> +        virReportError(VIR_ERR_DBUS_SERVICE,
> +                       _("TerminateMachine: %s"),
> +                       error.message ? error.message : _("unknown error"));
> +        goto cleanup;
> +    }
> +
>      ret = 0;
>  
>   cleanup:
> +    dbus_error_free(&error);
> +
>      VIR_FREE(machinename);
>      return ret;
>  }
> 

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]