Rather than copying and pasting lots of code, factor it into a
single helper function.
* src/phyp/phyp_driver.c (phypExecInt): New function.
(phypGetVIOSPartitionID, phypNumDomainsGeneric, phypGetLparID)
(phypGetLparMem, phypGetLparCPUGeneric, phypGetRemoteSlot)
(phypGetVIOSNextSlotNumber, phypAttachDevice)
(phypGetStoragePoolSize, phypStoragePoolNumOfVolumes)
(phypNumOfStoragePools, phypInterfaceDestroy)
(phypInterfaceDefineXML, phypInterfaceLookupByName)
(phypInterfaceIsActive, phypNumOfInterfaces): Use it.
---
src/phyp/phyp_driver.c | 353 +++++++++++-------------------------------------
1 files changed, 76 insertions(+), 277 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index cd0e5f9..d7043f3 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -223,2 +223,2 @@ phypExecBuffer(LIBSSH2_SESSION *session, virBufferPtr buf, int
*exit_status,
return ret;
}
+/* Convenience wrapper function */
+static int ATTRIBUTE_NONNULL(1)
+phypExecInt(LIBSSH2_SESSION *session, virBufferPtr buf, virConnectPtr conn,
+ int *result)
+{
+ char *str;
+ int ret;
+
+ str = phypExecBuffer(session, buf, &ret, conn, true);
+ if (!str || ret) {
+ VIR_FREE(str);
+ return -1;
+ }
+ ret = virStrToLong_i(str, NULL, 10, result);
+ VIR_FREE(str);
+ return ret;
+}
+
static int
phypGetSystemType(virConnectPtr conn)
{
@@ -250,10 +268,7 @@ phypGetVIOSPartitionID(virConnectPtr conn)
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
- char *ret = NULL;
- int exit_status = 0;
int id = -1;
- char *char_ptr;
char *managed_system = phyp_driver->managed_system;
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -262,20 +277,9 @@ phypGetVIOSPartitionID(virConnectPtr conn)
virBufferVSprintf(&buf, " -m %s", managed_system);
virBufferAddLit(&buf, " -r lpar -F lpar_id,lpar_env"
"|sed -n '/vioserver/ {\n s/,.*$//\n p\n}'");
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &id) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &id) < 0)
+ return -1;
return id;
-
- err:
- VIR_FREE(ret);
- return -1;
}
static virCapsPtr
@@ -337,10 +341,7 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int ndom = 0;
- char *char_ptr;
- char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
const char *state;
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -361,20 +362,9 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
virBufferVSprintf(&buf, " -m %s", managed_system);
virBufferVSprintf(&buf, " -F lpar_id,state %s |grep -c
'^[0-9]*'",
state);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &ndom) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &ndom) < 0)
+ return -1;
return ndom;
-
- err:
- VIR_FREE(ret);
- return -1;
}
/* This is a generic function that won't be used directly by
@@ -1294,30 +1284,16 @@ phypGetLparID(LIBSSH2_SESSION * session, const char
*managed_system,
{
phyp_driverPtr phyp_driver = conn->privateData;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int lpar_id = 0;
- char *char_ptr;
- char *ret = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "lssyscfg -r lpar");
if (system_type == HMC)
virBufferVSprintf(&buf, " -m %s", managed_system);
virBufferVSprintf(&buf, " --filter lpar_names=%s -F lpar_id", name);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &lpar_id) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &lpar_id) < 0)
+ lpar_id = -1;
return lpar_id;
-
- err:
- VIR_FREE(ret);
- return -1;
}
/* return the lpar name given a lpar_id and a managed system name */
@@ -1385,10 +1361,7 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int
lpar_id,
LIBSSH2_SESSION *session = connection_data->session;
phyp_driverPtr phyp_driver = conn->privateData;
int system_type = phyp_driver->system_type;
- char *ret = NULL;
- char *char_ptr;
int memory = 0;
- int exit_status = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (type != 1 && type != 0)
@@ -1400,21 +1373,9 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int
lpar_id,
virBufferVSprintf(&buf,
" -r mem --level lpar -F %s --filter lpar_ids=%d",
type ? "curr_mem" : "curr_max_mem", lpar_id);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &memory) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &memory) < 0)
+ return 0;
return memory;
-
- err:
- VIR_FREE(ret);
- return 0;
-
}
static unsigned long
@@ -1425,9 +1386,6 @@ phypGetLparCPUGeneric(virConnectPtr conn, const char
*managed_system,
LIBSSH2_SESSION *session = connection_data->session;
phyp_driverPtr phyp_driver = conn->privateData;
int system_type = phyp_driver->system_type;
- char *ret = NULL;
- char *char_ptr;
- int exit_status = 0;
int vcpus = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -1437,20 +1395,9 @@ phypGetLparCPUGeneric(virConnectPtr conn, const char
*managed_system,
virBufferVSprintf(&buf,
" -r proc --level lpar -F %s --filter lpar_ids=%d",
type ? "curr_max_procs" : "curr_procs",
lpar_id);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &vcpus) == -1)
- goto err;
-
- VIR_FREE(ret);
- return (unsigned long) vcpus;
-
- err:
- VIR_FREE(ret);
- return 0;
+ if (phypExecInt(session, &buf, conn, &vcpus) < 0)
+ return 0;
+ return vcpus;
}
static unsigned long
@@ -1488,10 +1435,7 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system,
LIBSSH2_SESSION *session = connection_data->session;
phyp_driverPtr phyp_driver = conn->privateData;
int system_type = phyp_driver->system_type;
- char *ret = NULL;
- char *char_ptr;
int remote_slot = 0;
- int exit_status = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "lshwres");
@@ -1499,20 +1443,9 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system,
virBufferVSprintf(&buf, " -m %s", managed_system);
virBufferVSprintf(&buf, " -r virtualio --rsubtype scsi -F "
"remote_slot_num --filter lpar_names=%s", lpar_name);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &remote_slot) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &remote_slot) < 0)
+ return -1;
return remote_slot;
-
- err:
- VIR_FREE(ret);
- return -1;
}
/* XXX - is this needed? */
@@ -1626,16 +1559,13 @@ phypGetVIOSNextSlotNumber(virConnectPtr conn)
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
int vios_id = phyp_driver->vios_id;
- int exit_status = 0;
- char *char_ptr;
- char *ret = NULL;
char *profile = NULL;
int slot = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (!(profile = phypGetLparProfile(conn, vios_id))) {
VIR_ERROR0(_("Unable to get VIOS profile name."));
- goto err;
+ return -1;
}
virBufferAddLit(&buf, "lssyscfg");
@@ -1649,20 +1579,9 @@ phypGetVIOSNextSlotNumber(virConnectPtr conn)
"virtual_serial_adapters|sed -e 's/\"//g' -e
"
"'s/,/\\n/g'|sed -e
's/\\(^[0-9][0-9]\\*\\).*$/\\1/'"
"|sort|tail -n 1", profile);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &slot) < 0)
+ return -1;
return slot + 1;
-
- err:
- VIR_FREE(ret);
- return -1;
}
static int
@@ -1802,7 +1721,6 @@ phypAttachDevice(virDomainPtr domain, const char *xml)
int system_type = phyp_driver->system_type;
int vios_id = phyp_driver->vios_id;
int exit_status = 0;
- char *char_ptr = NULL;
char *ret = NULL;
char *scsi_adapter = NULL;
int slot = 0;
@@ -1889,18 +1807,12 @@ phypAttachDevice(virDomainPtr domain, const char *xml)
virBufferVSprintf(&buf,
" slot_num,backing_device|grep %s|cut -d, -f1",
dev->data.disk->src);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
+ if (phypExecInt(session, &buf, conn, &slot) < 0)
goto err;
/* Listing all the virtual_scsi_adapter interfaces, the new adapter must
* be appended to this list
* */
- VIR_FREE(ret);
virBufferAddLit(&buf, "lssyscfg");
if (system_type == HMC)
virBufferVSprintf(&buf, " -m %s", managed_system);
@@ -1924,10 +1836,7 @@ phypAttachDevice(virDomainPtr domain, const char *xml)
"\"virtual_scsi_adapters=%s,%d/client/%d/%s/0\"'",
domain_name, domain->id, ret, slot,
vios_id, vios_name);
- VIR_FREE(ret);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
+ if (phypExecInt(session, &buf, conn, &slot) < 0)
goto err;
/* Finally I add the new scsi adapter to VIOS using the same slot
@@ -2047,11 +1956,8 @@ phypGetStoragePoolSize(virConnectPtr conn, char *name)
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int vios_id = phyp_driver->vios_id;
- char *ret = NULL;
int sp_size = 0;
- char *char_ptr;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (system_type == HMC)
@@ -2064,20 +1970,9 @@ phypGetStoragePoolSize(virConnectPtr conn, char *name)
virBufferAddChar(&buf, '\'');
virBufferVSprintf(&buf, "|sed '1d; s/ //g'");
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &sp_size) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &sp_size) < 0)
+ return -1;
return sp_size;
-
- err:
- VIR_FREE(ret);
- return -1;
}
static int
@@ -2512,7 +2407,7 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const
volumes,
int i;
char *ret = NULL;
char *volumes_list = NULL;
- char *char_ptr2 = NULL;
+ char *char_ptr = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (system_type == HMC)
@@ -2534,16 +2429,16 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const
volumes,
volumes_list = ret;
while (got < nvolumes) {
- char_ptr2 = strchr(volumes_list, '\n');
+ char_ptr = strchr(volumes_list, '\n');
- if (char_ptr2) {
- *char_ptr2 = '\0';
+ if (char_ptr) {
+ *char_ptr = '\0';
if ((volumes[got++] = strdup(volumes_list)) == NULL) {
virReportOOMError();
goto err;
}
- char_ptr2++;
- volumes_list = char_ptr2;
+ char_ptr++;
+ volumes_list = char_ptr;
} else
break;
}
@@ -2567,12 +2462,9 @@ phypStoragePoolNumOfVolumes(virStoragePoolPtr pool)
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int nvolumes = 0;
- char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
int vios_id = phyp_driver->vios_id;
- char *char_ptr;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (system_type == HMC)
@@ -2582,23 +2474,11 @@ phypStoragePoolNumOfVolumes(virStoragePoolPtr pool)
if (system_type == HMC)
virBufferAddChar(&buf, '\'');
virBufferVSprintf(&buf, "|grep -c '^.*$'");
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &nvolumes) == -1)
- goto err;
+ if (phypExecInt(session, &buf, conn, &nvolumes) < 0)
+ return -1;
/* We need to remove 2 line from the header text output */
- nvolumes -= 2;
-
- VIR_FREE(ret);
- return nvolumes;
-
- err:
- VIR_FREE(ret);
- return -1;
+ return nvolumes - 2;
}
static int
@@ -2684,12 +2564,9 @@ phypNumOfStoragePools(virConnectPtr conn)
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int nsp = 0;
- char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
int vios_id = phyp_driver->vios_id;
- char *char_ptr;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (system_type == HMC)
@@ -2702,20 +2579,9 @@ phypNumOfStoragePools(virConnectPtr conn)
virBufferAddChar(&buf, '\'');
virBufferVSprintf(&buf, "|grep -c '^.*$'");
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &nsp) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &nsp) < 0)
+ return -1;
return nsp;
-
- err:
- VIR_FREE(ret);
- return -1;
}
static int
@@ -2732,7 +2598,7 @@ phypListStoragePools(virConnectPtr conn, char **const pools, int
npools)
int i;
char *ret = NULL;
char *storage_pools = NULL;
- char *char_ptr2 = NULL;
+ char *char_ptr = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (system_type == HMC)
@@ -2752,16 +2618,16 @@ phypListStoragePools(virConnectPtr conn, char **const pools, int
npools)
storage_pools = ret;
while (got < npools) {
- char_ptr2 = strchr(storage_pools, '\n');
+ char_ptr = strchr(storage_pools, '\n');
- if (char_ptr2) {
- *char_ptr2 = '\0';
+ if (char_ptr) {
+ *char_ptr = '\0';
if ((pools[got++] = strdup(storage_pools)) == NULL) {
virReportOOMError();
goto err;
}
- char_ptr2++;
- storage_pools = char_ptr2;
+ char_ptr++;
+ storage_pools = char_ptr;
} else
break;
}
@@ -2934,7 +2800,6 @@ phypInterfaceDestroy(virInterfacePtr iface,
int exit_status = 0;
int slot_num = 0;
int lpar_id = 0;
- char *char_ptr;
char *ret = NULL;
/* Getting the remote slot number */
@@ -2947,17 +2812,10 @@ phypInterfaceDestroy(virInterfacePtr iface,
" -r virtualio --rsubtype eth --level lpar "
" -F mac_addr,slot_num|"
" sed -n '/%s/ s/^.*,//p'", iface->mac);
- ret = phypExecBuffer(session, &buf, &exit_status, iface->conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot_num) == -1)
+ if (phypExecInt(session, &buf, iface->conn, &slot_num) < 0)
goto err;
/* Getting the remote slot number */
- VIR_FREE(ret);
-
virBufferAddLit(&buf, "lshwres ");
if (system_type == HMC)
virBufferVSprintf(&buf, "-m %s ", managed_system);
@@ -2966,17 +2824,10 @@ phypInterfaceDestroy(virInterfacePtr iface,
" -r virtualio --rsubtype eth --level lpar "
" -F mac_addr,lpar_id|"
" sed -n '/%s/ s/^.*,//p'", iface->mac);
- ret = phypExecBuffer(session, &buf, &exit_status, iface->conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &lpar_id) == -1)
+ if (phypExecInt(session, &buf, iface->conn, &lpar_id) < 0)
goto err;
/* excluding interface */
- VIR_FREE(ret);
-
virBufferAddLit(&buf, "chhwres ");
if (system_type == HMC)
virBufferVSprintf(&buf, "-m %s ", managed_system);
@@ -3010,7 +2861,6 @@ phypInterfaceDefineXML(virConnectPtr conn, const char *xml,
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- char *char_ptr;
int slot = 0;
char *ret = NULL;
char name[PHYP_IFACENAME_SIZE];
@@ -3029,20 +2879,13 @@ phypInterfaceDefineXML(virConnectPtr conn, const char *xml,
" -r virtualio --rsubtype slot --level slot"
" -Fslot_num --filter lpar_names=%s"
" |sort|tail -n 1", def->name);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
+ if (phypExecInt(session, &buf, conn, &slot) < 0)
goto err;
/* The next free slot itself: */
slot++;
/* Now adding the new network interface */
- VIR_FREE(ret);
-
virBufferAddLit(&buf, "chhwres ");
if (system_type == HMC)
virBufferVSprintf(&buf, "-m %s ", managed_system);
@@ -3129,7 +2972,6 @@ phypInterfaceLookupByName(virConnectPtr conn, const char *name)
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- char *char_ptr;
char *ret = NULL;
int slot = 0;
int lpar_id = 0;
@@ -3145,17 +2987,10 @@ phypInterfaceLookupByName(virConnectPtr conn, const char *name)
" -r virtualio --rsubtype slot --level slot "
" -F drc_name,slot_num |"
" sed -n '/%s/ s/^.*,//p'", name);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
+ if (phypExecInt(session, &buf, conn, &slot) < 0)
goto err;
/*Getting the lpar_id for the interface */
- VIR_FREE(ret);
-
virBufferAddLit(&buf, "lshwres ");
if (system_type == HMC)
virBufferVSprintf(&buf, "-m %s ", managed_system);
@@ -3164,12 +2999,7 @@ phypInterfaceLookupByName(virConnectPtr conn, const char *name)
" -r virtualio --rsubtype slot --level slot "
" -F drc_name,lpar_id |"
" sed -n '/%s/ s/^.*,//p'", name);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &lpar_id) == -1)
+ if (phypExecInt(session, &buf, conn, &lpar_id) < 0)
goto err;
/*Getting the interface mac */
@@ -3181,7 +3011,6 @@ phypInterfaceLookupByName(virConnectPtr conn, const char *name)
" -r virtualio --rsubtype eth --level lpar "
" -F lpar_id,slot_num,mac_addr|"
" sed -n '/%d,%d/ s/^.*,//p'", lpar_id, slot);
- VIR_FREE(ret);
ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
if (exit_status < 0 || ret == NULL)
@@ -3209,10 +3038,7 @@ phypInterfaceIsActive(virInterfacePtr iface)
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
- int exit_status = 0;
int state = 0;
- char *char_ptr;
- char *ret = NULL;
virBufferAddLit(&buf, "lshwres ");
if (system_type == HMC)
@@ -3222,21 +3048,9 @@ phypInterfaceIsActive(virInterfacePtr iface)
" -r virtualio --rsubtype eth --level lpar "
" -F mac_addr,state |"
" sed -n '/%s/ s/^.*,//p'", iface->mac);
- ret = phypExecBuffer(session, &buf, &exit_status, iface->conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &state) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, iface->conn, &state) < 0)
+ return -1;
return state;
-
- err:
- VIR_FREE(ret);
- return -1;
-
}
static int
@@ -3253,7 +3067,7 @@ phypListInterfaces(virConnectPtr conn, char **const names, int
nnames)
int i;
char *ret = NULL;
char *networks = NULL;
- char *char_ptr2 = NULL;
+ char *char_ptr = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "lshwres");
@@ -3272,16 +3086,16 @@ phypListInterfaces(virConnectPtr conn, char **const names, int
nnames)
networks = ret;
while (got < nnames) {
- char_ptr2 = strchr(networks, '\n');
+ char_ptr = strchr(networks, '\n');
- if (char_ptr2) {
- *char_ptr2 = '\0';
+ if (char_ptr) {
+ *char_ptr = '\0';
if ((names[got++] = strdup(networks)) == NULL) {
virReportOOMError();
goto err;
}
- char_ptr2++;
- networks = char_ptr2;
+ char_ptr++;
+ networks = char_ptr;
} else {
break;
}
@@ -3306,10 +3120,7 @@ phypNumOfInterfaces(virConnectPtr conn)
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
int vios_id = phyp_driver->vios_id;
- int exit_status = 0;
int nnets = 0;
- char *char_ptr;
- char *ret = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "lshwres ");
@@ -3319,21 +3130,9 @@ phypNumOfInterfaces(virConnectPtr conn)
virBufferVSprintf(&buf,
"-r virtualio --rsubtype eth --level lpar|"
"grep -v lpar_id=%d|grep -c lpar_name", vios_id);
- ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
-
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- if (virStrToLong_i(ret, &char_ptr, 10, &nnets) == -1)
- goto err;
-
- VIR_FREE(ret);
+ if (phypExecInt(session, &buf, conn, &nnets) < 0)
+ return -1;
return nnets;
-
- err:
- VIR_FREE(ret);
- return -1;
-
}
static int
@@ -3438,7 +3237,7 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int
nnames)
int i;
char *ret = NULL;
char *domains = NULL;
- char *char_ptr2 = NULL;
+ char *char_ptr = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "lssyscfg -r lpar");
@@ -3455,16 +3254,16 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int
nnames)
domains = ret;
while (got < nnames) {
- char_ptr2 = strchr(domains, '\n');
+ char_ptr = strchr(domains, '\n');
- if (char_ptr2) {
- *char_ptr2 = '\0';
+ if (char_ptr) {
+ *char_ptr = '\0';
if ((names[got++] = strdup(domains)) == NULL) {
virReportOOMError();
goto err;
}
- char_ptr2++;
- domains = char_ptr2;
+ char_ptr++;
+ domains = char_ptr;
} else
break;
}
--
1.7.4.2