[libvirt] [PATCH] Add missing checks for whether the connection is open in dispatcher

Daniel P. Berrange berrange at redhat.com
Wed Apr 13 14:58:21 UTC 2011


Many functions did not check for whether a connection was
open. Replace the macro which obscures control flow, with
explicit checks, and ensure all dispatcher code has checks.

* daemon/remote.c: Add connection checks
---
 daemon/remote.c |  986 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 959 insertions(+), 27 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 8a2a71f..2a56d91 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -432,11 +432,6 @@ remoteDispatchOpen(struct qemud_server *server,
     return rc;
 }
 
-#define CHECK_CONN(client)                                              \
-    if (!client->conn) {                                                \
-        remoteDispatchFormatError(rerr, "%s", _("connection not open")); \
-        return -1;                                                      \
-    }
 
 static int
 remoteDispatchClose(struct qemud_server *server ATTRIBUTE_UNUSED,
@@ -464,6 +459,12 @@ remoteDispatchSupportsFeature(struct qemud_server *server ATTRIBUTE_UNUSED,
                               remote_error *rerr,
                               remote_supports_feature_args *args, remote_supports_feature_ret *ret)
 {
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     ret->supported = virDrvSupportsFeature(conn, args->feature);
 
     if (ret->supported == -1) {
@@ -484,6 +485,11 @@ remoteDispatchGetType(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     const char *type;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     type = virConnectGetType(conn);
     if (type == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -513,6 +519,11 @@ remoteDispatchGetVersion(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     unsigned long hvVer;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (virConnectGetVersion(conn, &hvVer) == -1) {
         remoteDispatchConnError(rerr, conn);
         return -1;
@@ -533,6 +544,11 @@ remoteDispatchGetLibVersion(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     unsigned long libVer;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (virConnectGetLibVersion(conn, &libVer) == -1) {
         remoteDispatchConnError(rerr, conn);
         return -1;
@@ -553,6 +569,11 @@ remoteDispatchGetHostname(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     char *hostname;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     hostname = virConnectGetHostname(conn);
     if (hostname == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -573,7 +594,11 @@ remoteDispatchGetUri(struct qemud_server *server ATTRIBUTE_UNUSED,
                      remote_get_uri_ret *ret)
 {
     char *uri;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     uri = virConnectGetURI(conn);
     if (uri == NULL) {
@@ -597,6 +622,11 @@ remoteDispatchGetSysinfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     unsigned int flags;
     char *sysinfo;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     flags = args->flags;
     sysinfo = virConnectGetSysinfo(conn, flags);
     if (sysinfo == NULL) {
@@ -619,6 +649,11 @@ remoteDispatchGetMaxVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     char *type;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     type = args->type ? *args->type : NULL;
     ret->max_vcpus = virConnectGetMaxVcpus(conn, type);
     if (ret->max_vcpus == -1) {
@@ -640,6 +675,11 @@ remoteDispatchNodeGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNodeInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (virNodeGetInfo(conn, &info) == -1) {
         remoteDispatchConnError(rerr, conn);
         return -1;
@@ -668,6 +708,11 @@ remoteDispatchGetCapabilities(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     char *caps;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     caps = virConnectGetCapabilities(conn);
     if (caps == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -689,6 +734,11 @@ remoteDispatchNodeGetCellsFreeMemory(struct qemud_server *server ATTRIBUTE_UNUSE
 {
     int err;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->maxCells > REMOTE_NODE_MAX_CELLS) {
         remoteDispatchFormatError(rerr,
                                    "%s", _("maxCells > REMOTE_NODE_MAX_CELLS"));
@@ -727,6 +777,11 @@ remoteDispatchNodeGetFreeMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     unsigned long long freeMem;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     freeMem = virNodeGetFreeMemory(conn);
     if (freeMem == 0) {
         remoteDispatchConnError(rerr, conn);
@@ -750,6 +805,11 @@ remoteDispatchDomainGetSchedulerType(struct qemud_server *server ATTRIBUTE_UNUSE
     char *type;
     int nparams;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -782,6 +842,11 @@ remoteDispatchDomainGetSchedulerParameters(struct qemud_server *server ATTRIBUTE
     virSchedParameterPtr params;
     int i, r, nparams;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->nparams;
 
     if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
@@ -866,6 +931,11 @@ remoteDispatchDomainSetSchedulerParameters(struct qemud_server *server ATTRIBUTE
     int i, r, nparams;
     virSchedParameterPtr params;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->params.params_len;
 
     if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
@@ -933,6 +1003,11 @@ remoteDispatchDomainBlockStats(struct qemud_server *server ATTRIBUTE_UNUSED,
     char *path;
     struct _virDomainBlockStats stats;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -969,6 +1044,11 @@ remoteDispatchDomainInterfaceStats(struct qemud_server *server ATTRIBUTE_UNUSED,
     char *path;
     struct _virDomainInterfaceStats stats;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1008,6 +1088,11 @@ remoteDispatchDomainMemoryStats(struct qemud_server *server ATTRIBUTE_UNUSED,
     struct _virDomainMemoryStat *stats;
     unsigned int nr_stats, i;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->maxStats > REMOTE_DOMAIN_MEMORY_STATS_MAX) {
         remoteDispatchFormatError(rerr, "%s",
                                _("maxStats > REMOTE_DOMAIN_MEMORY_STATS_MAX"));
@@ -1068,6 +1153,11 @@ remoteDispatchDomainBlockPeek(struct qemud_server *server ATTRIBUTE_UNUSED,
     size_t size;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1118,6 +1208,11 @@ remoteDispatchDomainMemoryPeek(struct qemud_server *server ATTRIBUTE_UNUSED,
     size_t size;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1164,6 +1259,11 @@ remoteDispatchDomainAttachDevice(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1190,6 +1290,11 @@ remoteDispatchDomainAttachDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1216,6 +1321,11 @@ remoteDispatchDomainUpdateDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1242,6 +1352,11 @@ remoteDispatchDomainCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1296,6 +1411,11 @@ remoteDispatchDomainCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = virDomainCreateXML(conn, args->xml_desc, args->flags);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1319,6 +1439,11 @@ remoteDispatchDomainDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = virDomainDefineXML(conn, args->xml);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1342,6 +1467,11 @@ remoteDispatchDomainDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1368,6 +1498,11 @@ remoteDispatchDomainDetachDevice(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1395,6 +1530,11 @@ remoteDispatchDomainDetachDeviceFlags(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1422,6 +1562,11 @@ remoteDispatchDomainDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1448,6 +1593,11 @@ remoteDispatchDomainXmlFromNative(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   remote_domain_xml_from_native_args *args,
                                   remote_domain_xml_from_native_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     /* remoteDispatchClientRequest will free this. */
     ret->domainXml = virConnectDomainXMLFromNative(conn,
                                                    args->nativeFormat,
@@ -1469,6 +1619,11 @@ remoteDispatchDomainXmlToNative(struct qemud_server *server ATTRIBUTE_UNUSED,
                                 remote_domain_xml_to_native_args *args,
                                 remote_domain_xml_to_native_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     /* remoteDispatchClientRequest will free this. */
     ret->nativeConfig = virConnectDomainXMLToNative(conn,
                                                     args->nativeFormat,
@@ -1493,6 +1648,11 @@ remoteDispatchDomainGetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1520,6 +1680,11 @@ remoteDispatchDomainGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainPtr dom;
     virDomainInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1554,6 +1719,11 @@ remoteDispatchDomainGetMaxMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1581,6 +1751,11 @@ remoteDispatchDomainGetMaxVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1609,6 +1784,11 @@ remoteDispatchDomainGetSecurityLabel(struct qemud_server *server ATTRIBUTE_UNUSE
     virDomainPtr dom;
     virSecurityLabelPtr seclabel;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1654,6 +1834,11 @@ remoteDispatchNodeGetSecurityModel(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecurityModel secmodel;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     memset(&secmodel, 0, sizeof secmodel);
     if (virNodeGetSecurityModel(conn, &secmodel) == -1) {
         remoteDispatchConnError(rerr, conn);
@@ -1688,6 +1873,11 @@ remoteDispatchDomainGetOsType(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1719,6 +1909,11 @@ remoteDispatchDomainGetVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
     unsigned char *cpumaps = NULL;
     int info_len, i;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1797,6 +1992,11 @@ remoteDispatchDomainGetVcpusFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1829,6 +2029,11 @@ remoteDispatchDomainMigratePrepare(struct qemud_server *server ATTRIBUTE_UNUSED,
     char **uri_out;
     char *dname;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     uri_in = args->uri_in == NULL ? NULL : *args->uri_in;
     dname = args->dname == NULL ? NULL : *args->dname;
 
@@ -1875,6 +2080,11 @@ remoteDispatchDomainMigratePerform(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainPtr dom;
     char *dname;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -1908,7 +2118,11 @@ remoteDispatchDomainMigrateFinish(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   remote_domain_migrate_finish_ret *ret)
 {
     virDomainPtr ddom;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ddom = virDomainMigrateFinish(conn, args->dname,
                                   args->cookie.cookie_val,
@@ -1940,7 +2154,11 @@ remoteDispatchDomainMigratePrepare2(struct qemud_server *server ATTRIBUTE_UNUSED
     char *uri_in;
     char **uri_out;
     char *dname;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     uri_in = args->uri_in == NULL ? NULL : *args->uri_in;
     dname = args->dname == NULL ? NULL : *args->dname;
@@ -1980,7 +2198,11 @@ remoteDispatchDomainMigrateFinish2(struct qemud_server *server ATTRIBUTE_UNUSED,
                                    remote_domain_migrate_finish2_ret *ret)
 {
     virDomainPtr ddom;
-    CHECK_CONN (client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ddom = virDomainMigrateFinish2(conn, args->dname,
                                    args->cookie.cookie_val,
@@ -2011,7 +2233,11 @@ remoteDispatchDomainMigratePrepareTunnel(struct qemud_server *server ATTRIBUTE_U
     int r;
     char *dname;
     struct qemud_client_stream *stream;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dname = args->dname == NULL ? NULL : *args->dname;
 
@@ -2049,6 +2275,10 @@ remoteDispatchListDefinedDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
                                  remote_list_defined_domains_args *args,
                                  remote_list_defined_domains_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_DOMAIN_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -2085,6 +2315,11 @@ remoteDispatchDomainLookupById(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = virDomainLookupByID(conn, args->id);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2107,6 +2342,11 @@ remoteDispatchDomainLookupByName(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = virDomainLookupByName(conn, args->name);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2129,6 +2369,11 @@ remoteDispatchDomainLookupByUuid(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = virDomainLookupByUUID(conn, (unsigned char *) args->uuid);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2149,6 +2394,10 @@ remoteDispatchNumOfDefinedDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   void *args ATTRIBUTE_UNUSED,
                                   remote_num_of_defined_domains_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfDefinedDomains(conn);
     if (ret->num == -1) {
@@ -2171,6 +2420,11 @@ remoteDispatchDomainPinVcpu(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainPtr dom;
     int rv;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2206,6 +2460,11 @@ remoteDispatchDomainReboot(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2230,6 +2489,10 @@ remoteDispatchDomainRestore(struct qemud_server *server ATTRIBUTE_UNUSED,
                             remote_domain_restore_args *args,
                             void *ret ATTRIBUTE_UNUSED)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (virDomainRestore(conn, args->from) == -1) {
         remoteDispatchConnError(rerr, conn);
@@ -2250,6 +2513,11 @@ remoteDispatchDomainResume(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2276,6 +2544,11 @@ remoteDispatchDomainSave(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2302,6 +2575,11 @@ remoteDispatchDomainCoreDump(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2328,6 +2606,11 @@ remoteDispatchDomainSetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2354,6 +2637,11 @@ remoteDispatchDomainSetMaxMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2380,6 +2668,11 @@ remoteDispatchDomainSetMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2406,6 +2699,11 @@ remoteDispatchDomainSetMemoryFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2438,6 +2736,11 @@ remoteDispatchDomainSetMemoryParameters(struct qemud_server *server
     virMemoryParameterPtr params;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->params.params_len;
     flags = args->flags;
 
@@ -2533,6 +2836,11 @@ remoteDispatchDomainGetMemoryParameters(struct qemud_server *server
     int i, r, nparams;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->nparams;
     flags = args->flags;
 
@@ -2649,6 +2957,11 @@ remoteDispatchDomainSetBlkioParameters(struct qemud_server *server
     virBlkioParameterPtr params;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->params.params_len;
     flags = args->flags;
 
@@ -2744,6 +3057,11 @@ remoteDispatchDomainGetBlkioParameters(struct qemud_server *server
     int i, r, nparams;
     unsigned int flags;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nparams = args->nparams;
     flags = args->flags;
 
@@ -2854,6 +3172,11 @@ remoteDispatchDomainSetVcpus(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2880,6 +3203,11 @@ remoteDispatchDomainSetVcpusFlags(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2906,6 +3234,11 @@ remoteDispatchDomainShutdown(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2932,6 +3265,11 @@ remoteDispatchDomainSuspend(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2958,6 +3296,11 @@ remoteDispatchDomainUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -2982,6 +3325,10 @@ remoteDispatchListDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   remote_list_defined_networks_args *args,
                                   remote_list_defined_networks_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -3016,6 +3363,10 @@ remoteDispatchListDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
                           remote_list_domains_args *args,
                           remote_list_domains_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxids > REMOTE_DOMAIN_ID_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -3051,6 +3402,11 @@ remoteDispatchDomainManagedSave(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3077,6 +3433,11 @@ remoteDispatchDomainHasManagedSaveImage(struct qemud_server *server ATTRIBUTE_UN
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3104,6 +3465,11 @@ remoteDispatchDomainManagedSaveRemove(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3128,6 +3494,10 @@ remoteDispatchListNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
                            remote_list_networks_args *args,
                            remote_list_networks_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -3164,6 +3534,11 @@ remoteDispatchNetworkCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3190,6 +3565,11 @@ remoteDispatchNetworkCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = virNetworkCreateXML(conn, args->xml);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3212,6 +3592,11 @@ remoteDispatchNetworkDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = virNetworkDefineXML(conn, args->xml);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3234,6 +3619,11 @@ remoteDispatchNetworkDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3260,6 +3650,11 @@ remoteDispatchNetworkDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3288,6 +3683,11 @@ remoteDispatchNetworkGetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3314,6 +3714,11 @@ remoteDispatchNetworkGetBridgeName(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3342,6 +3747,11 @@ remoteDispatchNetworkLookupByName(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = virNetworkLookupByName(conn, args->name);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3364,6 +3774,11 @@ remoteDispatchNetworkLookupByUuid(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = virNetworkLookupByUUID(conn, (unsigned char *) args->uuid);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3386,8 +3801,13 @@ remoteDispatchNetworkSetAutostart(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
-    net = get_nonnull_network(conn, args->net);
-    if (net == NULL) {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
+    net = get_nonnull_network(conn, args->net);
+    if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
         return -1;
     }
@@ -3412,6 +3832,11 @@ remoteDispatchNetworkUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNetworkPtr net;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     net = get_nonnull_network(conn, args->net);
     if (net == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3436,6 +3861,10 @@ remoteDispatchNumOfDefinedNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
                                    void *args ATTRIBUTE_UNUSED,
                                    remote_num_of_defined_networks_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfDefinedNetworks(conn);
     if (ret->num == -1) {
@@ -3455,6 +3884,10 @@ remoteDispatchNumOfDomains(struct qemud_server *server ATTRIBUTE_UNUSED,
                            void *args ATTRIBUTE_UNUSED,
                            remote_num_of_domains_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfDomains(conn);
     if (ret->num == -1) {
@@ -3474,6 +3907,10 @@ remoteDispatchNumOfNetworks(struct qemud_server *server ATTRIBUTE_UNUSED,
                             void *args ATTRIBUTE_UNUSED,
                             remote_num_of_networks_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfNetworks(conn);
     if (ret->num == -1) {
@@ -3495,6 +3932,10 @@ remoteDispatchNumOfInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED,
                               void *args ATTRIBUTE_UNUSED,
                               remote_num_of_interfaces_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfInterfaces(conn);
     if (ret->num == -1) {
@@ -3514,6 +3955,10 @@ remoteDispatchListInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED,
                              remote_list_interfaces_args *args,
                              remote_list_interfaces_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_INTERFACE_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -3548,6 +3993,10 @@ remoteDispatchNumOfDefinedInterfaces(struct qemud_server *server ATTRIBUTE_UNUSE
                                      void *args ATTRIBUTE_UNUSED,
                                      remote_num_of_defined_interfaces_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfDefinedInterfaces(conn);
     if (ret->num == -1) {
@@ -3567,6 +4016,10 @@ remoteDispatchListDefinedInterfaces(struct qemud_server *server ATTRIBUTE_UNUSED
                                     remote_list_defined_interfaces_args *args,
                                     remote_list_defined_interfaces_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_DEFINED_INTERFACE_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -3603,6 +4056,11 @@ remoteDispatchInterfaceLookupByName(struct qemud_server *server ATTRIBUTE_UNUSED
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = virInterfaceLookupByName(conn, args->name);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3625,6 +4083,11 @@ remoteDispatchInterfaceLookupByMacString(struct qemud_server *server ATTRIBUTE_U
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = virInterfaceLookupByMACString(conn, args->mac);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3647,6 +4110,11 @@ remoteDispatchInterfaceGetXmlDesc(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = get_nonnull_interface(conn, args->iface);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3675,6 +4143,11 @@ remoteDispatchInterfaceDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = virInterfaceDefineXML(conn, args->xml, args->flags);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3697,6 +4170,11 @@ remoteDispatchInterfaceUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = get_nonnull_interface(conn, args->iface);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3723,6 +4201,11 @@ remoteDispatchInterfaceCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = get_nonnull_interface(conn, args->iface);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3749,6 +4232,11 @@ remoteDispatchInterfaceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = get_nonnull_interface(conn, args->iface);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -3775,6 +4263,11 @@ remoteDispatchAuthList(struct qemud_server *server,
                        void *args ATTRIBUTE_UNUSED,
                        remote_auth_list_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     ret->types.types_len = 1;
     if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0) {
         remoteDispatchOOMError(rerr);
@@ -4572,6 +5065,10 @@ remoteDispatchListDefinedStoragePools(struct qemud_server *server ATTRIBUTE_UNUS
                                       remote_list_defined_storage_pools_args *args,
                                       remote_list_defined_storage_pools_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr, "%s",
@@ -4606,6 +5103,10 @@ remoteDispatchListStoragePools(struct qemud_server *server ATTRIBUTE_UNUSED,
                                remote_list_storage_pools_args *args,
                                remote_list_storage_pools_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_STORAGE_POOL_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -4640,6 +5141,11 @@ remoteDispatchFindStoragePoolSources(struct qemud_server *server ATTRIBUTE_UNUSE
                                      remote_find_storage_pool_sources_args *args,
                                      remote_find_storage_pool_sources_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     ret->xml =
         virConnectFindStoragePoolSources(conn,
                                          args->type,
@@ -4665,6 +5171,11 @@ remoteDispatchStoragePoolCreate(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4691,6 +5202,11 @@ remoteDispatchStoragePoolCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = virStoragePoolCreateXML(conn, args->xml, args->flags);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4713,6 +5229,11 @@ remoteDispatchStoragePoolDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = virStoragePoolDefineXML(conn, args->xml, args->flags);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4735,6 +5256,11 @@ remoteDispatchStoragePoolBuild(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4762,6 +5288,11 @@ remoteDispatchStoragePoolDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4788,6 +5319,11 @@ remoteDispatchStoragePoolDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4814,6 +5350,11 @@ remoteDispatchStoragePoolRefresh(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4841,6 +5382,11 @@ remoteDispatchStoragePoolGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     virStoragePoolPtr pool;
     virStoragePoolInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4874,6 +5420,11 @@ remoteDispatchStoragePoolDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4902,6 +5453,11 @@ remoteDispatchStoragePoolGetAutostart(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4929,6 +5485,11 @@ remoteDispatchStoragePoolLookupByName(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = virStoragePoolLookupByName(conn, args->name);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4951,6 +5512,11 @@ remoteDispatchStoragePoolLookupByUuid(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = virStoragePoolLookupByUUID(conn, (unsigned char *) args->uuid);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -4974,6 +5540,11 @@ remoteDispatchStoragePoolLookupByVolume(struct qemud_server *server ATTRIBUTE_UN
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5004,6 +5575,11 @@ remoteDispatchStoragePoolSetAutostart(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5030,6 +5606,11 @@ remoteDispatchStoragePoolUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5054,6 +5635,10 @@ remoteDispatchNumOfStoragePools(struct qemud_server *server ATTRIBUTE_UNUSED,
                                 void *args ATTRIBUTE_UNUSED,
                                 remote_num_of_storage_pools_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfStoragePools(conn);
     if (ret->num == -1) {
@@ -5073,6 +5658,10 @@ remoteDispatchNumOfDefinedStoragePools(struct qemud_server *server ATTRIBUTE_UNU
                                        void *args ATTRIBUTE_UNUSED,
                                        remote_num_of_defined_storage_pools_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfDefinedStoragePools(conn);
     if (ret->num == -1) {
@@ -5094,6 +5683,11 @@ remoteDispatchStoragePoolListVolumes(struct qemud_server *server ATTRIBUTE_UNUSE
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->maxnames > REMOTE_STORAGE_VOL_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
                                    "%s", _("maxnames > REMOTE_STORAGE_VOL_NAME_LIST_MAX"));
@@ -5139,6 +5733,11 @@ remoteDispatchStoragePoolNumOfVolumes(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5175,6 +5774,11 @@ remoteDispatchStorageVolCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5206,6 +5810,11 @@ remoteDispatchStorageVolCreateXmlFrom(struct qemud_server *server ATTRIBUTE_UNUS
     virStoragePoolPtr pool;
     virStorageVolPtr clonevol, newvol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5246,6 +5855,11 @@ remoteDispatchStorageVolDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5273,6 +5887,11 @@ remoteDispatchStorageVolWipe(struct qemud_server *server ATTRIBUTE_UNUSED,
     int retval = -1;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5305,6 +5924,11 @@ remoteDispatchStorageVolGetInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     virStorageVolPtr vol;
     virStorageVolInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5337,6 +5961,11 @@ remoteDispatchStorageVolDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5366,6 +5995,11 @@ remoteDispatchStorageVolGetPath(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5396,6 +6030,11 @@ remoteDispatchStorageVolLookupByName(struct qemud_server *server ATTRIBUTE_UNUSE
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5426,6 +6065,11 @@ remoteDispatchStorageVolLookupByKey(struct qemud_server *server ATTRIBUTE_UNUSED
 {
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = virStorageVolLookupByKey(conn, args->key);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5449,6 +6093,11 @@ remoteDispatchStorageVolLookupByPath(struct qemud_server *server ATTRIBUTE_UNUSE
 {
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = virStorageVolLookupByPath(conn, args->path);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5474,7 +6123,10 @@ remoteDispatchNodeNumOfDevices(struct qemud_server *server ATTRIBUTE_UNUSED,
                                remote_node_num_of_devices_args *args,
                                remote_node_num_of_devices_ret *ret)
 {
-    CHECK_CONN(client);
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virNodeNumOfDevices(conn,
                                    args->cap ? *args->cap : NULL,
@@ -5497,7 +6149,10 @@ remoteDispatchNodeListDevices(struct qemud_server *server ATTRIBUTE_UNUSED,
                               remote_node_list_devices_args *args,
                               remote_node_list_devices_ret *ret)
 {
-    CHECK_CONN(client);
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_NODE_DEVICE_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -5536,7 +6191,10 @@ remoteDispatchNodeDeviceLookupByName(struct qemud_server *server ATTRIBUTE_UNUSE
 {
     virNodeDevicePtr dev;
 
-    CHECK_CONN(client);
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5560,7 +6218,11 @@ remoteDispatchNodeDeviceDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED,
                                 remote_node_device_dump_xml_ret *ret)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5591,7 +6253,11 @@ remoteDispatchNodeDeviceGetParent(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNodeDevicePtr dev;
     const char *parent;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5635,7 +6301,11 @@ remoteDispatchNodeDeviceNumOfCaps(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   remote_node_device_num_of_caps_ret *ret)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5665,7 +6335,11 @@ remoteDispatchNodeDeviceListCaps(struct qemud_server *server ATTRIBUTE_UNUSED,
                                  remote_node_device_list_caps_ret *ret)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5712,7 +6386,11 @@ remoteDispatchNodeDeviceDettach(struct qemud_server *server ATTRIBUTE_UNUSED,
                                 void *ret ATTRIBUTE_UNUSED)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5741,7 +6419,11 @@ remoteDispatchNodeDeviceReAttach(struct qemud_server *server ATTRIBUTE_UNUSED,
                                  void *ret ATTRIBUTE_UNUSED)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5770,7 +6452,11 @@ remoteDispatchNodeDeviceReset(struct qemud_server *server ATTRIBUTE_UNUSED,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virNodeDevicePtr dev;
-    CHECK_CONN(client);
+
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
@@ -5800,6 +6486,11 @@ remoteDispatchNodeDeviceCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNodeDevicePtr dev;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dev = virNodeDeviceCreateXML(conn, args->xml_desc, args->flags);
     if (dev == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5824,6 +6515,11 @@ remoteDispatchNodeDeviceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNodeDevicePtr dev;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dev = virNodeDeviceLookupByName(conn, args->name);
     if (dev == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5851,6 +6547,11 @@ static int remoteDispatchStorageVolUpload(struct qemud_server *server ATTRIBUTE_
     struct qemud_client_stream *stream = NULL;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5898,6 +6599,11 @@ static int remoteDispatchStorageVolDownload(struct qemud_server *server ATTRIBUT
     struct qemud_client_stream *stream = NULL;
     virStorageVolPtr vol;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     vol = get_nonnull_storage_vol(conn, args->vol);
     if (vol == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -5946,9 +6652,13 @@ remoteDispatchDomainEventsRegister(struct qemud_server *server ATTRIBUTE_UNUSED,
                                    void *args ATTRIBUTE_UNUSED,
                                    remote_domain_events_register_ret *ret ATTRIBUTE_UNUSED)
 {
-    CHECK_CONN(client);
     int callbackID;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] != -1) {
         remoteDispatchFormatError(rerr, _("domain event %d already registered"), VIR_DOMAIN_EVENT_ID_LIFECYCLE);
         return -1;
@@ -5977,7 +6687,10 @@ remoteDispatchDomainEventsDeregister(struct qemud_server *server ATTRIBUTE_UNUSE
                                      void *args ATTRIBUTE_UNUSED,
                                      remote_domain_events_deregister_ret *ret ATTRIBUTE_UNUSED)
 {
-    CHECK_CONN(client);
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] == -1) {
         remoteDispatchFormatError(rerr, _("domain event %d not registered"), VIR_DOMAIN_EVENT_ID_LIFECYCLE);
@@ -6067,6 +6780,11 @@ remoteDispatchNumOfSecrets(struct qemud_server *server ATTRIBUTE_UNUSED,
                            void *args ATTRIBUTE_UNUSED,
                            remote_num_of_secrets_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     ret->num = virConnectNumOfSecrets(conn);
     if (ret->num == -1) {
         remoteDispatchConnError(rerr, conn);
@@ -6085,6 +6803,11 @@ remoteDispatchListSecrets(struct qemud_server *server ATTRIBUTE_UNUSED,
                           remote_list_secrets_args *args,
                           remote_list_secrets_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->maxuuids > REMOTE_SECRET_UUID_LIST_MAX) {
         remoteDispatchFormatError(rerr, "%s",
                                    _("maxuuids > REMOTE_SECRET_UUID_LIST_MAX"));
@@ -6118,6 +6841,11 @@ remoteDispatchSecretDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = virSecretDefineXML(conn, args->xml, args->flags);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6142,6 +6870,11 @@ remoteDispatchSecretGetValue(struct qemud_server *server ATTRIBUTE_UNUSED,
     size_t value_size;
     unsigned char *value;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = get_nonnull_secret(conn, args->secret);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6172,6 +6905,11 @@ remoteDispatchSecretGetXmlDesc(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = get_nonnull_secret(conn, args->secret);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6198,6 +6936,11 @@ remoteDispatchSecretLookupByUuid(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = virSecretLookupByUUID(conn, (unsigned char *)args->uuid);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6220,6 +6963,11 @@ remoteDispatchSecretSetValue(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = get_nonnull_secret(conn, args->secret);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6247,6 +6995,11 @@ remoteDispatchSecretUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = get_nonnull_secret(conn, args->secret);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6273,6 +7026,11 @@ remoteDispatchSecretLookupByUsage(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virSecretPtr secret;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     secret = virSecretLookupByUsage(conn, args->usageType, args->usageID);
     if (secret == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6295,6 +7053,11 @@ static int remoteDispatchDomainIsActive(struct qemud_server *server ATTRIBUTE_UN
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->dom);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6323,6 +7086,11 @@ static int remoteDispatchDomainIsPersistent(struct qemud_server *server ATTRIBUT
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->dom);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6351,6 +7119,11 @@ static int remoteDispatchDomainIsUpdated(struct qemud_server *server ATTRIBUTE_U
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->dom);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6379,6 +7152,11 @@ static int remoteDispatchInterfaceIsActive(struct qemud_server *server ATTRIBUTE
 {
     virInterfacePtr iface;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     iface = get_nonnull_interface(conn, args->iface);
     if (iface == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6407,6 +7185,11 @@ static int remoteDispatchNetworkIsActive(struct qemud_server *server ATTRIBUTE_U
 {
     virNetworkPtr network;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     network = get_nonnull_network(conn, args->net);
     if (network == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6435,6 +7218,11 @@ static int remoteDispatchNetworkIsPersistent(struct qemud_server *server ATTRIBU
 {
     virNetworkPtr network;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     network = get_nonnull_network(conn, args->net);
     if (network == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6463,6 +7251,11 @@ static int remoteDispatchStoragePoolIsActive(struct qemud_server *server ATTRIBU
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6491,6 +7284,11 @@ static int remoteDispatchStoragePoolIsPersistent(struct qemud_server *server ATT
 {
     virStoragePoolPtr pool;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     pool = get_nonnull_storage_pool(conn, args->pool);
     if (pool == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6518,6 +7316,11 @@ static int remoteDispatchIsSecure(struct qemud_server *server ATTRIBUTE_UNUSED,
                                   void *args ATTRIBUTE_UNUSED,
                                   remote_is_secure_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     ret->secure = virConnectIsSecure(conn);
 
     if (ret->secure < 0) {
@@ -6540,6 +7343,11 @@ remoteDispatchCpuCompare(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     int result;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     result = virConnectCompareCPU(conn, args->xml, args->flags);
     if (result == VIR_CPU_COMPARE_ERROR) {
         remoteDispatchConnError(rerr, conn);
@@ -6562,6 +7370,11 @@ remoteDispatchCpuBaseline(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     char *cpu;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     cpu = virConnectBaselineCPU(conn,
                                 (const char **) args->xmlCPUs.xmlCPUs_val,
                                 args->xmlCPUs.xmlCPUs_len,
@@ -6589,6 +7402,11 @@ remoteDispatchDomainGetJobInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainPtr dom;
     virDomainJobInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6631,6 +7449,11 @@ remoteDispatchDomainAbortJob(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6660,6 +7483,11 @@ remoteDispatchDomainMigrateSetMaxDowntime(struct qemud_server *server ATTRIBUTE_
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6688,6 +7516,11 @@ remoteDispatchDomainMigrateSetMaxSpeed(struct qemud_server *server ATTRIBUTE_UNU
 {
     virDomainPtr dom;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6717,6 +7550,11 @@ remoteDispatchDomainSnapshotCreateXml(struct qemud_server *server ATTRIBUTE_UNUS
     virDomainSnapshotPtr snapshot;
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6751,6 +7589,11 @@ remoteDispatchDomainSnapshotDumpXml(struct qemud_server *server ATTRIBUTE_UNUSED
     virDomainSnapshotPtr snapshot = NULL;
     int rc = -1;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->snap.domain);
     if (domain == NULL)
         goto cleanup;
@@ -6788,6 +7631,11 @@ remoteDispatchDomainSnapshotNum(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6817,6 +7665,11 @@ remoteDispatchDomainSnapshotListNames(struct qemud_server *server ATTRIBUTE_UNUS
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->nameslen > REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX) {
         remoteDispatchFormatError(rerr, "%s",
                                    _("nameslen > REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX"));
@@ -6864,6 +7717,11 @@ remoteDispatchDomainSnapshotLookupByName(struct qemud_server *server ATTRIBUTE_U
     virDomainSnapshotPtr snapshot;
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6897,6 +7755,11 @@ remoteDispatchDomainHasCurrentSnapshot(struct qemud_server *server ATTRIBUTE_UNU
     virDomainPtr domain;
     int result;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6929,6 +7792,11 @@ remoteDispatchDomainSnapshotCurrent(struct qemud_server *server ATTRIBUTE_UNUSED
     virDomainSnapshotPtr snapshot;
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -6963,6 +7831,11 @@ remoteDispatchDomainRevertToSnapshot(struct qemud_server *server ATTRIBUTE_UNUSE
     virDomainSnapshotPtr snapshot = NULL;
     int rc = -1;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->snap.domain);
     if (domain == NULL)
         goto cleanup;
@@ -7000,6 +7873,11 @@ remoteDispatchDomainSnapshotDelete(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainSnapshotPtr snapshot = NULL;
     int rc = -1;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->snap.domain);
     if (domain == NULL)
         goto cleanup;
@@ -7034,9 +7912,13 @@ remoteDispatchDomainEventsRegisterAny(struct qemud_server *server ATTRIBUTE_UNUS
                                       remote_domain_events_register_any_args *args,
                                       void *ret ATTRIBUTE_UNUSED)
 {
-    CHECK_CONN(client);
     int callbackID;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->eventID >= VIR_DOMAIN_EVENT_ID_LAST ||
         args->eventID < 0) {
         remoteDispatchFormatError(rerr, _("unsupported event ID %d"), args->eventID);
@@ -7072,9 +7954,13 @@ remoteDispatchDomainEventsDeregisterAny(struct qemud_server *server ATTRIBUTE_UN
                                         remote_domain_events_deregister_any_args *args,
                                         void *ret ATTRIBUTE_UNUSED)
 {
-    CHECK_CONN(client);
     int callbackID = -1;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     if (args->eventID >= VIR_DOMAIN_EVENT_ID_LAST ||
         args->eventID < 0) {
         remoteDispatchFormatError(rerr, _("unsupported event ID %d"), args->eventID);
@@ -7109,6 +7995,11 @@ remoteDispatchNwfilterLookupByName(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNWFilterPtr nwfilter;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nwfilter = virNWFilterLookupByName(conn, args->name);
     if (nwfilter == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7131,6 +8022,11 @@ remoteDispatchNwfilterLookupByUuid(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNWFilterPtr nwfilter;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nwfilter = virNWFilterLookupByUUID(conn, (unsigned char *) args->uuid);
     if (nwfilter == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7154,6 +8050,11 @@ remoteDispatchNwfilterDefineXml(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNWFilterPtr nwfilter;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nwfilter = virNWFilterDefineXML(conn, args->xml);
     if (nwfilter == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7177,6 +8078,11 @@ remoteDispatchNwfilterUndefine(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNWFilterPtr nwfilter;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nwfilter = get_nonnull_nwfilter(conn, args->nwfilter);
     if (nwfilter == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7201,6 +8107,10 @@ remoteDispatchListNwfilters(struct qemud_server *server ATTRIBUTE_UNUSED,
                             remote_list_nwfilters_args *args,
                             remote_list_nwfilters_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     if (args->maxnames > REMOTE_NWFILTER_NAME_LIST_MAX) {
         remoteDispatchFormatError(rerr,
@@ -7238,6 +8148,11 @@ remoteDispatchNwfilterGetXmlDesc(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virNWFilterPtr nwfilter;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     nwfilter = get_nonnull_nwfilter(conn, args->nwfilter);
     if (nwfilter == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7265,6 +8180,10 @@ remoteDispatchNumOfNwfilters(struct qemud_server *server ATTRIBUTE_UNUSED,
                              void *args ATTRIBUTE_UNUSED,
                              remote_num_of_nwfilters_ret *ret)
 {
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     ret->num = virConnectNumOfNWFilters(conn);
     if (ret->num == -1) {
@@ -7288,6 +8207,11 @@ remoteDispatchDomainGetBlockInfo(struct qemud_server *server ATTRIBUTE_UNUSED,
     virDomainPtr dom;
     virDomainBlockInfo info;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     dom = get_nonnull_domain(conn, args->dom);
     if (dom == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7320,6 +8244,11 @@ qemuDispatchMonitorCommand(struct qemud_server *server ATTRIBUTE_UNUSED,
 {
     virDomainPtr domain;
 
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
+
     domain = get_nonnull_domain(conn, args->domain);
     if (domain == NULL) {
         remoteDispatchConnError(rerr, conn);
@@ -7352,7 +8281,10 @@ remoteDispatchDomainOpenConsole(struct qemud_server *server ATTRIBUTE_UNUSED,
     struct qemud_client_stream *stream;
     virDomainPtr dom;
 
-    CHECK_CONN (client);
+    if (!conn) {
+        remoteDispatchFormatError(rerr, "%s", _("connection not open"));
+        return -1;
+    }
 
     dom = get_nonnull_domain(conn, args->domain);
     if (dom == NULL) {
-- 
1.7.4.2




More information about the libvir-list mailing list