Commit 26e25d7d authored by Pavel Hrdina's avatar Pavel Hrdina

domain: ensure connection to libvirt

Fixes an bug that was introduced by <8e24f602>.
Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent bc5af5b4
......@@ -53,7 +53,7 @@ virtDBusConnectClose(virtDBusConnect *connect,
connect->connection = NULL;
}
static int
int
virtDBusConnectOpen(virtDBusConnect *connect,
sd_bus_error *error)
{
......
......@@ -26,6 +26,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
const char *uri,
const char *connectPath);
int
virtDBusConnectOpen(virtDBusConnect *connect,
sd_bus_error *error);
virtDBusConnect *
virtDBusConnectFree(virtDBusConnect *connect);
......
......@@ -19,6 +19,9 @@ virtDBusDomainGetName(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
const char *name = "";
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -44,6 +47,9 @@ virtDBusDomainGetUUID(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
char uuid[VIR_UUID_STRING_BUFLEN] = "";
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -66,6 +72,9 @@ virtDBusDomainGetId(sd_bus *bus VIRT_ATTR_UNUSED,
virtDBusConnect *connect = userdata;
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -86,6 +95,9 @@ virtDBusDomainGetVcpus(sd_bus *bus VIRT_ATTR_UNUSED,
virtDBusConnect *connect = userdata;
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -107,6 +119,9 @@ virtDBusDomainGetOsType(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
_cleanup_(virtDBusUtilFreep) char *os_type = NULL;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -132,6 +147,9 @@ virtDBusDomainGetActive(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int active;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -157,6 +175,9 @@ virtDBusDomainGetPersistent(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int persistent;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -183,6 +204,9 @@ virtDBusDomainGetState(sd_bus *bus VIRT_ATTR_UNUSED,
int state = 0;
const char *string;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -234,6 +258,9 @@ virtDBusDomainGetAutostart(sd_bus *bus VIRT_ATTR_UNUSED,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int autostart = 0;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection, path,
connect->domainPath);
if (domain == NULL)
......@@ -255,6 +282,9 @@ virtDBusDomainGetXMLDesc(sd_bus_message *message,
uint32_t flags;
int r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -300,6 +330,9 @@ virtDBusDomainGetStats(sd_bus_message *message,
if (r < 0)
return r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -336,6 +369,9 @@ virtDBusDomainShutdown(sd_bus_message *message,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -362,6 +398,9 @@ virtDBusDomainDestroy(sd_bus_message *message,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -393,6 +432,9 @@ virtDBusDomainReboot(sd_bus_message *message,
if (r < 0)
return r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -424,6 +466,9 @@ virtDBusDomainReset(sd_bus_message *message,
if (r < 0)
return r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -450,6 +495,9 @@ virtDBusDomainCreate(sd_bus_message *message,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......@@ -476,6 +524,9 @@ virtDBusDomainUndefine(sd_bus_message *message,
_cleanup_(virtDBusUtilVirDomainFreep) virDomainPtr domain = NULL;
int r;
if (virtDBusConnectOpen(connect, error) < 0)
return -1;
domain = virtDBusUtilVirDomainFromBusPath(connect->connection,
sd_bus_message_get_path(message),
connect->domainPath);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment