return ninterfaces;
}
+
+
+int
+virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
+ bool wantActive,
+ char **const names,
+ int maxnames)
+{
+ int nnames = 0;
+ size_t i;
+
+ for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
+ virInterfaceObjPtr obj = interfaces->objs[i];
+ virInterfaceObjLock(obj);
+ if (wantActive == virInterfaceObjIsActive(obj)) {
+ if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
+ virInterfaceObjUnlock(obj);
+ goto failure;
+ }
+ nnames++;
+ }
+ virInterfaceObjUnlock(obj);
+ }
+
+ return nnames;
+
+ failure:
+ while (--nnames >= 0)
+ VIR_FREE(names[nnames]);
+
+ return -1;
+}
return ninterfaces;
}
-static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
+static int testConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames)
{
testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
+ int nnames;
testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ nnames = virInterfaceObjGetNames(&privconn->ifaces, true, names, maxnames);
testDriverUnlock(privconn);
- return n;
-
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+ return nnames;
}
static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
return ninterfaces;
}
-static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int nnames)
+static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int maxnames)
{
testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
+ int nnames;
testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) < 0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ nnames = virInterfaceObjGetNames(&privconn->ifaces, false, names, maxnames);
testDriverUnlock(privconn);
- return n;
-
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+ return nnames;
}
static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn,