}
if (!(dmn = virNetDaemonNew()) ||
- virNetDaemonAddServer(dmn, srv) < 0) {
+ virNetDaemonAddServer(dmn, "libvirtd", srv) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
goto cleanup;
}
- if (virNetDaemonAddServer(dmn, srvAdm) < 0) {
+ if (virNetDaemonAddServer(dmn, "admin", srvAdm) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
goto error;
if (!(lockd->dmn = virNetDaemonNew()) ||
- virNetDaemonAddServer(lockd->dmn, srv) < 0)
+ virNetDaemonAddServer(lockd->dmn, "virtlockd", srv) < 0)
goto error;
if (!(lockd->lockspaces = virHashCreate(VIR_LOCK_DAEMON_NUM_LOCKSPACES,
goto error;
if (!(srv = virNetDaemonAddServerPostExec(lockd->dmn,
+ "virtlockd",
virLockDaemonClientNew,
virLockDaemonClientNewPostExecRestart,
virLockDaemonClientPreExecRestart,
goto cleanup;
}
- srv = virNetDaemonGetServer(lockDaemon->dmn, 0);
+ srv = virNetDaemonGetServer(lockDaemon->dmn, "virtlockd");
if ((rv = virLockDaemonSetupNetworkingSystemD(srv) < 0)) {
ret = VIR_LOCK_DAEMON_ERR_NETWORK;
goto cleanup;
goto cleanup;
}
} else if (rv == 1) {
- srv = virNetDaemonGetServer(lockDaemon->dmn, 0);
+ srv = virNetDaemonGetServer(lockDaemon->dmn, "virtlockd");
}
if (timeout != -1) {
goto error;
if (!(logd->dmn = virNetDaemonNew()) ||
- virNetDaemonAddServer(logd->dmn, logd->srv) < 0)
+ virNetDaemonAddServer(logd->dmn, "virtlogd", logd->srv) < 0)
goto error;
if (!(logd->handler = virLogHandlerNew(privileged,
goto error;
if (!(logd->srv = virNetDaemonAddServerPostExec(logd->dmn,
+ "virtlogd",
virLogDaemonClientNew,
virLogDaemonClientNewPostExecRestart,
virLogDaemonClientPreExecRestart,
goto error;
if (!(ctrl->daemon = virNetDaemonNew()) ||
- virNetDaemonAddServer(ctrl->daemon, srv) < 0)
+ virNetDaemonAddServer(ctrl->daemon, "LXC", srv) < 0)
goto error;
virNetDaemonUpdateServices(ctrl->daemon, true);
#include "virnetserver.h"
#include "virnetservermdns.h"
#include "virdbus.h"
+#include "virhash.h"
#include "virstring.h"
#include "virsystemd.h"
int sigwrite;
int sigwatch;
- size_t nservers;
- virNetServerPtr *servers;
+ virHashTablePtr servers;
virJSONValuePtr srvObject;
bool quit;
if (dmn->sigwatch > 0)
virEventRemoveHandle(dmn->sigwatch);
- for (i = 0; i < dmn->nservers; i++)
- virObjectUnref(dmn->servers[i]);
- VIR_FREE(dmn->servers);
+ virHashFree(dmn->servers);
virJSONValueFree(dmn->srvObject);
}
if (!(dmn = virObjectLockableNew(virNetDaemonClass)))
return NULL;
+ if (!(dmn->servers = virHashCreate(5, virObjectFreeHashData)))
+ goto error;
+
dmn->sigwrite = dmn->sigread = -1;
dmn->privileged = geteuid() == 0;
dmn->autoShutdownInhibitFd = -1;
int
-virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr srv)
+virNetDaemonAddServer(virNetDaemonPtr dmn,
+ const char *serverName,
+ virNetServerPtr srv)
{
int ret = -1;
virObjectLock(dmn);
- if (VIR_APPEND_ELEMENT_COPY(dmn->servers, dmn->nservers, srv) < 0)
+ if (virHashAddEntry(dmn->servers, serverName, srv) < 0)
goto cleanup;
virObjectRef(srv);
- ret = dmn->nservers - 1;
+
+ ret = 0;
cleanup:
virObjectUnlock(dmn);
return ret;
}
-/*
- * Separate function merely for the purpose of unified error
- * reporting.
- */
-static virNetServerPtr
-virNetDaemonGetServerInternal(virNetDaemonPtr dmn,
- int subServerID)
-{
- if (subServerID < 0 || subServerID >= dmn->nservers) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Invalid server ID: %d"),
- subServerID);
- return NULL;
- }
-
- return virObjectRef(dmn->servers[subServerID]);
-}
-
virNetServerPtr
virNetDaemonGetServer(virNetDaemonPtr dmn,
- int subServerID)
+ const char *serverName)
{
virNetServerPtr srv = NULL;
virObjectLock(dmn);
- srv = virNetDaemonGetServerInternal(dmn, subServerID);
+ srv = virObjectRef(virHashLookup(dmn->servers, serverName));
virObjectUnlock(dmn);
return srv;
virNetServerPtr
virNetDaemonAddServerPostExec(virNetDaemonPtr dmn,
+ const char *serverName,
virNetServerClientPrivNew clientPrivNew,
virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart,
virNetServerClientPrivPreExecRestart clientPrivPreExecRestart,
virJSONValueFree(dmn->srvObject);
dmn->srvObject = NULL;
}
- } else {
+ } else if (virJSONValueObjectGetByType(dmn->srvObject,
+ "min_workers",
+ VIR_JSON_TYPE_NUMBER)) {
object = dmn->srvObject;
dmn->srvObject = NULL;
+ } else {
+ int ret = virJSONValueObjectRemoveKey(dmn->srvObject,
+ serverName,
+ &object);
+ if (ret != 1) {
+ if (ret == 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Server '%s' not found in JSON"), serverName);
+ }
+ goto error;
+ }
+
}
srv = virNetServerNewPostExecRestart(object,
clientPrivFree,
clientPrivOpaque);
- if (!srv || VIR_APPEND_ELEMENT_COPY(dmn->servers, dmn->nservers, srv) < 0)
+ if (!srv)
+ goto error;
+
+ if (virHashAddEntry(dmn->servers, serverName, srv) < 0)
goto error;
virJSONValueFree(object);
}
+static int
+daemonServerCompare(const virHashKeyValuePair *a, const virHashKeyValuePair *b)
+{
+ const char *as = a->key;
+ const char *bs = b->key;
+
+ return strcmp(as, bs);
+}
+
virJSONValuePtr
virNetDaemonPreExecRestart(virNetDaemonPtr dmn)
{
- virJSONValuePtr object, srvArray = NULL;
- size_t i;
+ size_t i = 0;
+ virJSONValuePtr object = NULL;
+ virJSONValuePtr srvObj = NULL;
+ virHashKeyValuePairPtr srvArray = NULL;
virObjectLock(dmn);
if (!(object = virJSONValueNewObject()))
goto error;
- if (!(srvArray = virJSONValueNewArray()) ||
- virJSONValueObjectAppend(object, "servers", srvArray) < 0)
+ if (!(srvObj = virJSONValueNewObject()))
goto error;
- for (i = 0; i < dmn->nservers; i++) {
- virJSONValuePtr srvJSON = NULL;
- srvJSON = virNetServerPreExecRestart(dmn->servers[i]);
+ if (virJSONValueObjectAppend(object, "servers", srvObj) < 0) {
+ virJSONValueFree(srvObj);
+ goto error;
+ }
+
+ if (!(srvArray = virHashGetItems(dmn->servers, daemonServerCompare)))
+ goto error;
+
+ for (i = 0; srvArray[i].key; i++) {
+ virNetServerPtr server = virHashLookup(dmn->servers, srvArray[i].key);
+ virJSONValuePtr srvJSON;
+ if (!server)
+ goto error;
+
+ srvJSON = virNetServerPreExecRestart(server);
if (!srvJSON)
goto error;
- if (virJSONValueArrayAppend(srvArray, srvJSON) < 0) {
+ if (virJSONValueObjectAppend(srvObj, srvArray[i].key, srvJSON) < 0) {
virJSONValueFree(srvJSON);
goto error;
}
return object;
error:
+ VIR_FREE(srvArray);
virJSONValueFree(object);
- virJSONValueFree(srvArray);
virObjectUnlock(dmn);
return NULL;
}
virObjectUnlock(dmn);
}
+static int
+daemonServerUpdateServices(void *payload,
+ const void *key ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+ bool *enable = opaque;
+ virNetServerPtr srv = payload;
+
+ virNetServerUpdateServices(srv, *enable);
+ return 0;
+}
+
void
virNetDaemonUpdateServices(virNetDaemonPtr dmn,
bool enabled)
{
- size_t i;
-
virObjectLock(dmn);
- for (i = 0; i < dmn->nservers; i++)
- virNetServerUpdateServices(dmn->servers[i], enabled);
+ virHashForEach(dmn->servers, daemonServerUpdateServices, &enabled);
virObjectUnlock(dmn);
}
+static int
+daemonServerRun(void *payload,
+ const void *key ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ virNetServerPtr srv = payload;
+
+ return virNetServerStart(srv);
+};
+
+static int
+daemonServerProcessClients(void *payload,
+ const void *key ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ virNetServerPtr srv = payload;
+
+ virNetServerProcessClients(srv);
+ return 0;
+}
+
void
virNetDaemonRun(virNetDaemonPtr dmn)
{
int timerid = -1;
bool timerActive = false;
- size_t i;
virObjectLock(dmn);
goto cleanup;
}
- for (i = 0; i < dmn->nservers; i++) {
- if (virNetServerStart(dmn->servers[i]) < 0)
- goto cleanup;
- }
+ if (virHashForEach(dmn->servers, daemonServerRun, NULL) < 0)
+ goto cleanup;
dmn->quit = false;
}
virObjectLock(dmn);
- for (i = 0; i < dmn->nservers; i++)
- virNetServerProcessClients(dmn->servers[i]);
+ virHashForEach(dmn->servers, daemonServerProcessClients, NULL);
}
cleanup:
virObjectUnlock(dmn);
}
+static int
+daemonServerClose(void *payload,
+ const void *key ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ virNetServerPtr srv = payload;
+
+ virNetServerClose(srv);
+ return 0;
+}
void
virNetDaemonClose(virNetDaemonPtr dmn)
{
- size_t i;
-
if (!dmn)
return;
virObjectLock(dmn);
- for (i = 0; i < dmn->nservers; i++)
- virNetServerClose(dmn->servers[i]);
+ virHashForEach(dmn->servers, daemonServerClose, NULL);
virObjectUnlock(dmn);
}
-bool
-virNetDaemonHasClients(virNetDaemonPtr dmn)
+static int
+daemonServerHasClients(void *payload,
+ const void *key ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED)
{
- size_t i = 0;
+ virNetServerPtr srv = payload;
- for (i = 0; i < dmn->nservers; i++) {
- if (virNetServerHasClients(dmn->servers[i]))
- return true;
- }
+ return virNetServerHasClients(srv);
+}
- return false;
+bool
+virNetDaemonHasClients(virNetDaemonPtr dmn)
+{
+ return virHashForEach(dmn->servers, daemonServerHasClients, NULL) > 0;
}
virNetDaemonPtr virNetDaemonNew(void);
-int virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr);
+int virNetDaemonAddServer(virNetDaemonPtr dmn,
+ const char *serverName,
+ virNetServerPtr srv);
virNetServerPtr virNetDaemonAddServerPostExec(virNetDaemonPtr dmn,
+ const char *serverName,
virNetServerClientPrivNew clientPrivNew,
virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart,
virNetServerClientPrivPreExecRestart clientPrivPreExecRestart,
bool virNetDaemonHasClients(virNetDaemonPtr dmn);
virNetServerPtr virNetDaemonGetServer(virNetDaemonPtr dmn,
- int subServerID);
+ const char *serverName);
#endif /* __VIR_NET_DAEMON_H__ */
--- /dev/null
+{
+ "servers":
+ {
+ "testServer0":
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ "testServer1":
+ {
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ }
+}
{
- "servers": [
- {
+ "servers": {
+ "testServer0": {
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
}
]
},
- {
+ "testServer1": {
"min_workers": 2,
"max_workers": 50,
"priority_workers": 5,
}
]
}
- ]
+ }
}
--- /dev/null
+{
+ "servers": {
+ "testServer0": {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ "testServer1": {
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ }
+}
{
- "servers": [
- {
+ "servers": {
+ "testServer0": {
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
}
]
}
- ]
+ }
}
{
- "servers": [
- {
+ "servers": {
+ "testServer0": {
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
}
]
}
- ]
+ }
}
{
- "servers": [
- {
+ "servers": {
+ "testServer0": {
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
}
]
}
- ]
+ }
}
{
- "servers": [
- {
- "min_workers": 10,
- "max_workers": 50,
- "priority_workers": 5,
- "max_clients": 100,
- "keepaliveInterval": 120,
- "keepaliveCount": 5,
- "services": [
- {
- "auth": 0,
- "readonly": true,
- "nrequests_client_max": 2,
- "socks": [
- {
- "fd": 100,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
+ "servers": {
+ "testServer0": {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
]
- },
- {
- "auth": 2,
- "readonly": false,
- "nrequests_client_max": 5,
- "socks": [
- {
- "fd": 101,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
- ]
- }
- ],
- "clients": [
- {
- "auth": 1,
- "readonly": true,
- "nrequests_max": 15,
- "sock": {
- "fd": 102,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- },
- {
- "auth": 2,
- "readonly": true,
- "nrequests_max": 66,
- "sock": {
- "fd": 103,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- }
- ]
- },
- {
- "min_workers": 2,
- "max_workers": 50,
- "priority_workers": 5,
- "max_clients": 100,
- "keepaliveInterval": 120,
- "keepaliveCount": 5,
- "services": [
- {
- "auth": 0,
- "readonly": true,
- "nrequests_client_max": 2,
- "socks": [
- {
- "fd": 100,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
- ]
- },
- {
- "auth": 2,
- "readonly": false,
- "nrequests_client_max": 5,
- "socks": [
- {
- "fd": 101,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
- ]
- }
- ],
- "clients": [
- {
- "auth": 1,
- "readonly": true,
- "nrequests_max": 15,
- "sock": {
- "fd": 102,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- },
- {
- "auth": 2,
- "readonly": true,
- "nrequests_max": 66,
- "sock": {
- "fd": 103,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- }
- ]
+ },
+ "testServer1": {
+ {
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ }
}
- ]
}
goto cleanup;
}
-static char *testGenerateJSON(void)
+static char *testGenerateJSON(const char *server_name)
{
virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL;
if (!has_ipv4 && !has_ipv6)
return NULL;
- if (!(srv = testCreateServer(
- has_ipv4 ? "127.0.0.1" : "::1",
- has_ipv4 ? AF_INET : AF_INET6)))
+ if (!(srv = testCreateServer(has_ipv4 ? "127.0.0.1" : "::1",
+ has_ipv4 ? AF_INET : AF_INET6)))
goto cleanup;
if (!(dmn = virNetDaemonNew()))
goto cleanup;
- if (virNetDaemonAddServer(dmn, srv) < 0)
+ if (virNetDaemonAddServer(dmn, server_name, srv) < 0)
goto cleanup;
if (!(json = virNetDaemonPreExecRestart(dmn)))
struct testExecRestartData {
const char *jsonfile;
+ const char **serverNames;
int nservers;
bool pass;
};
goto cleanup;
for (i = 0; i < data->nservers; i++) {
- if (!(srv = virNetDaemonAddServerPostExec(dmn,
+ if (!(srv = virNetDaemonAddServerPostExec(dmn, data->serverNames[i],
NULL, NULL, NULL,
NULL, NULL)))
goto cleanup;
if (virtTestCompareToFile(outjsonstr, outfile) < 0)
goto cleanup;
- if (!data->pass) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Test should've failed");
- goto cleanup;
- }
-
ret = 0;
cleanup:
if (ret < 0) {
- if (!data->pass)
+ if (!data->pass) {
+ VIR_TEST_DEBUG("Got expected error: %s\n",
+ virGetLastErrorMessage());
+ virResetLastError();
ret = 0;
- else
- virDispatchError(NULL);
+ }
+ } else if (!data->pass) {
+ VIR_TEST_DEBUG("Test should have failed\n");
+ ret = -1;
}
VIR_FREE(infile);
VIR_FREE(outfile);
mymain(void)
{
int ret = 0;
+ const char *server_names[] = { "testServer0", "testServer1" };
if (virInitialize() < 0 ||
virEventRegisterDefaultImpl() < 0) {
* numbers with 100, 101, 102, 103.
*/
if (getenv("VIR_GENERATE_JSON")) {
- char *json = testGenerateJSON();
+ char *json = testGenerateJSON(server_names[0]);
if (!json)
return EXIT_FAILURE;
return ret;
}
-# define EXEC_RESTART_TEST_FULL(file, servers, pass) \
- do { \
- struct testExecRestartData data = { \
- file, servers, pass \
- }; \
- if (virtTestRun("ExecRestart " file, \
- testExecRestart, &data) < 0) \
- ret = -1; \
+# define EXEC_RESTART_TEST_FULL(file, nservers, pass) \
+ do { \
+ struct testExecRestartData data = { \
+ file, server_names, nservers, pass \
+ }; \
+ if (virtTestRun("ExecRestart " file, \
+ testExecRestart, &data) < 0) \
+ ret = -1; \
} while (0)
-# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1, true)
+# define EXEC_RESTART_TEST(file, N) EXEC_RESTART_TEST_FULL(file, N, true)
+# define EXEC_RESTART_TEST_FAIL(file, N) EXEC_RESTART_TEST_FULL(file, N, false)
+
# ifdef WITH_AVAHI
- EXEC_RESTART_TEST("initial");
+ EXEC_RESTART_TEST("initial", 1);
# endif
- EXEC_RESTART_TEST("initial-nomdns");
- EXEC_RESTART_TEST("anon-clients");
-
- EXEC_RESTART_TEST_FULL("anon-clients", 2, false);
- EXEC_RESTART_TEST_FULL("admin-nomdns", 2, true);
+ EXEC_RESTART_TEST("initial-nomdns", 1);
+ EXEC_RESTART_TEST("anon-clients", 1);
+ EXEC_RESTART_TEST("admin-nomdns", 2);
+ EXEC_RESTART_TEST("admin-server-names", 2);
+ EXEC_RESTART_TEST_FAIL("anon-clients", 2);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}