mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
systemd: don't report an error if the guest is already terminated
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.
This commit is contained in:
parent
f7afeddce9
commit
b3e4401dc6
@ -338,18 +338,22 @@ int virSystemdTerminateMachine(const char *name,
|
|||||||
int ret;
|
int ret;
|
||||||
DBusConnection *conn;
|
DBusConnection *conn;
|
||||||
char *machinename = NULL;
|
char *machinename = NULL;
|
||||||
|
virError error;
|
||||||
|
|
||||||
|
memset(&error, 0, sizeof(error));
|
||||||
|
|
||||||
ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
|
ret = virDBusIsServiceEnabled("org.freedesktop.machine1");
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
|
if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) < 0)
|
||||||
return ret;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(conn = virDBusGetSystemBus()))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
|
if (!(conn = virDBusGetSystemBus()))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(machinename = virSystemdMakeMachineName(name, drivername, privileged)))
|
if (!(machinename = virSystemdMakeMachineName(name, drivername, privileged)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -366,7 +370,7 @@ int virSystemdTerminateMachine(const char *name,
|
|||||||
VIR_DEBUG("Attempting to terminate machine via systemd");
|
VIR_DEBUG("Attempting to terminate machine via systemd");
|
||||||
if (virDBusCallMethod(conn,
|
if (virDBusCallMethod(conn,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&error,
|
||||||
"org.freedesktop.machine1",
|
"org.freedesktop.machine1",
|
||||||
"/org/freedesktop/machine1",
|
"/org/freedesktop/machine1",
|
||||||
"org.freedesktop.machine1.Manager",
|
"org.freedesktop.machine1.Manager",
|
||||||
@ -375,9 +379,18 @@ int virSystemdTerminateMachine(const char *name,
|
|||||||
machinename) < 0)
|
machinename) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (error.code == VIR_ERR_ERROR &&
|
||||||
|
!STREQ_NULLABLE("org.freedesktop.machine1.NoSuchMachine",
|
||||||
|
error.str1)) {
|
||||||
|
virReportErrorObject(&error);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virResetError(&error);
|
||||||
|
|
||||||
VIR_FREE(machinename);
|
VIR_FREE(machinename);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user