cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
virStoragePoolInfo info;
- int ret;
size_t i;
- bool functionReturn = false;
+ bool ret = false;
size_t stringLength = 0, nameStrLength = 0;
size_t autostartStrLength = 0, persistStrLength = 0;
size_t stateStrLength = 0, capStrLength = 0;
double val;
const char *unit;
- /* Create the capacity output string */
val = vshPrettyCapacity(info.capacity, &unit);
- ret = virAsprintf(&poolInfoTexts[i].capacity,
- "%.2lf %s", val, unit);
- if (ret < 0)
- /* An error occurred creating the string, return */
- goto asprintf_failure;
+ if (virAsprintf(&poolInfoTexts[i].capacity,
+ "%.2lf %s", val, unit) < 0)
+ goto cleanup;
- /* Create the allocation output string */
val = vshPrettyCapacity(info.allocation, &unit);
- ret = virAsprintf(&poolInfoTexts[i].allocation,
- "%.2lf %s", val, unit);
- if (ret < 0)
- /* An error occurred creating the string, return */
- goto asprintf_failure;
+ if (virAsprintf(&poolInfoTexts[i].allocation,
+ "%.2lf %s", val, unit) < 0)
+ goto cleanup;
- /* Create the available space output string */
val = vshPrettyCapacity(info.available, &unit);
- ret = virAsprintf(&poolInfoTexts[i].available,
- "%.2lf %s", val, unit);
- if (ret < 0)
- /* An error occurred creating the string, return */
- goto asprintf_failure;
+ if (virAsprintf(&poolInfoTexts[i].available,
+ "%.2lf %s", val, unit) < 0)
+ goto cleanup;
} else {
/* Capacity related information isn't available */
poolInfoTexts[i].capacity = vshStrdup(ctl, _("-"));
}
/* Cleanup and return */
- functionReturn = true;
+ ret = true;
goto cleanup;
}
/* Create the output template. Each column is sized according to
* the longest string.
*/
- ret = virAsprintf(&outputStr,
- " %%-%lus %%-%lus %%-%lus %%-%lus %%%lus %%%lus %%%lus\n",
- (unsigned long) nameStrLength,
- (unsigned long) stateStrLength,
- (unsigned long) autostartStrLength,
- (unsigned long) persistStrLength,
- (unsigned long) capStrLength,
- (unsigned long) allocStrLength,
- (unsigned long) availStrLength);
- if (ret < 0) {
- /* An error occurred creating the string, return */
- goto asprintf_failure;
- }
+ if (virAsprintf(&outputStr,
+ " %%-%lus %%-%lus %%-%lus %%-%lus %%%lus %%%lus %%%lus\n",
+ (unsigned long) nameStrLength,
+ (unsigned long) stateStrLength,
+ (unsigned long) autostartStrLength,
+ (unsigned long) persistStrLength,
+ (unsigned long) capStrLength,
+ (unsigned long) allocStrLength,
+ (unsigned long) availStrLength) < 0)
+ goto cleanup;
/* Display the header */
vshPrint(ctl, outputStr, _("Name"), _("State"), _("Autostart"),
}
/* Cleanup and return */
- functionReturn = true;
- goto cleanup;
-
-asprintf_failure:
- /* Display an appropriate error message then cleanup and return */
- switch (errno) {
- case ENOMEM:
- /* Couldn't allocate memory */
- vshError(ctl, "%s", _("Out of memory"));
- break;
- default:
- /* Some other error */
- vshError(ctl, _("virAsprintf failed (errno %d)"), errno);
- }
- functionReturn = false;
+ ret = true;
cleanup:
VIR_FREE(outputStr);
VIR_FREE(poolInfoTexts);
vshStoragePoolListFree(list);
- return functionReturn;
+ return ret;
}
/*
double val;
bool details = vshCommandOptBool(cmd, "details");
size_t i;
- int ret;
- bool functionReturn = false;
+ bool ret = false;
int stringLength = 0;
size_t allocStrLength = 0, capStrLength = 0;
size_t nameStrLength = 0, pathStrLength = 0;
volInfoTexts[i].type = vshStrdup(ctl,
vshVolumeTypeToString(volumeInfo.type));
- /* Create the capacity output string */
val = vshPrettyCapacity(volumeInfo.capacity, &unit);
- ret = virAsprintf(&volInfoTexts[i].capacity,
- "%.2lf %s", val, unit);
- if (ret < 0) {
- /* An error occurred creating the string, return */
- goto asprintf_failure;
- }
-
- /* Create the allocation output string */
+ if (virAsprintf(&volInfoTexts[i].capacity,
+ "%.2lf %s", val, unit) < 0)
+ goto cleanup;
+
val = vshPrettyCapacity(volumeInfo.allocation, &unit);
- ret = virAsprintf(&volInfoTexts[i].allocation,
- "%.2lf %s", val, unit);
- if (ret < 0) {
- /* An error occurred creating the string, return */
- goto asprintf_failure;
- }
+ if (virAsprintf(&volInfoTexts[i].allocation,
+ "%.2lf %s", val, unit) < 0)
+ goto cleanup;
}
/* Remember the largest length for each output string.
}
/* Cleanup and return */
- functionReturn = true;
+ ret = true;
goto cleanup;
}
vshDebug(ctl, VSH_ERR_DEBUG,
"Longest allocation string = %zu chars\n", allocStrLength);
- /* Create the output template */
- ret = virAsprintf(&outputStr,
- " %%-%lus %%-%lus %%-%lus %%%lus %%%lus\n",
- (unsigned long) nameStrLength,
- (unsigned long) pathStrLength,
- (unsigned long) typeStrLength,
- (unsigned long) capStrLength,
- (unsigned long) allocStrLength);
- if (ret < 0) {
- /* An error occurred creating the string, return */
- goto asprintf_failure;
- }
+ if (virAsprintf(&outputStr,
+ " %%-%lus %%-%lus %%-%lus %%%lus %%%lus\n",
+ (unsigned long) nameStrLength,
+ (unsigned long) pathStrLength,
+ (unsigned long) typeStrLength,
+ (unsigned long) capStrLength,
+ (unsigned long) allocStrLength) < 0)
+ goto cleanup;
/* Display the header */
vshPrint(ctl, outputStr, _("Name"), _("Path"), _("Type"),
}
/* Cleanup and return */
- functionReturn = true;
- goto cleanup;
-
-asprintf_failure:
-
- /* Display an appropriate error message then cleanup and return */
- switch (errno) {
- case ENOMEM:
- /* Couldn't allocate memory */
- vshError(ctl, "%s", _("Out of memory"));
- break;
- default:
- /* Some other error */
- vshError(ctl, _("virAsprintf failed (errno %d)"), errno);
- }
- functionReturn = false;
+ ret = true;
cleanup:
vshStorageVolListFree(list);
/* Return the desired value */
- return functionReturn;
+ return ret;
}
/*