mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 08:55:22 +00:00
util: Add exitstatus parameter to virCommandRunRegex
Rather than have virCommandRun just spit out the error, allow callers to decide to pass the exitstatus so the caller can make intelligent decisions based on the error. (cherry picked from commit 8b1049473317c09d34b3ce9671d0f9e91dd4f1c0)
This commit is contained in:
parent
2d302d7902
commit
5e08a5386a
@ -261,7 +261,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
|
||||
|
||||
if (virCommandRunRegex(cmd, 1, regexes, vars,
|
||||
virStorageBackendFileSystemNetFindPoolSourcesFunc,
|
||||
state, NULL) < 0)
|
||||
state, NULL, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
@ -398,7 +398,8 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
|
||||
vars,
|
||||
virStorageBackendLogicalMakeVol,
|
||||
&cbdata,
|
||||
"lvs") < 0)
|
||||
"lvs",
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
@ -511,10 +512,10 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList)
|
||||
cmd = virCommandNewArgList(PVS,
|
||||
"--noheadings",
|
||||
"-o", "pv_name,vg_name",
|
||||
NULL);
|
||||
NULL, NULL);
|
||||
if (virCommandRunRegex(cmd, 1, regexes, vars,
|
||||
virStorageBackendLogicalFindPoolSourcesFunc,
|
||||
sourceList, "pvs") < 0)
|
||||
sourceList, "pvs", NULL) < 0)
|
||||
goto cleanup;
|
||||
ret = 0;
|
||||
|
||||
@ -799,7 +800,8 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
vars,
|
||||
virStorageBackendLogicalRefreshPoolFunc,
|
||||
pool,
|
||||
"vgs") < 0)
|
||||
"vgs",
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
@ -2900,6 +2900,7 @@ virCommandSetDryRun(virBufferPtr buf,
|
||||
* needs to return 0 on success
|
||||
* @data: additional data that will be passed to the callback function
|
||||
* @prefix: prefix that will be skipped at the beginning of each line
|
||||
* @exitstatus: allows the caller to handle command run exit failures
|
||||
*
|
||||
* Run an external program.
|
||||
*
|
||||
@ -2917,7 +2918,8 @@ virCommandRunRegex(virCommandPtr cmd,
|
||||
int *nvars,
|
||||
virCommandRunRegexFunc func,
|
||||
void *data,
|
||||
const char *prefix)
|
||||
const char *prefix,
|
||||
int *exitstatus)
|
||||
{
|
||||
int err;
|
||||
regex_t *reg;
|
||||
@ -2959,7 +2961,7 @@ virCommandRunRegex(virCommandPtr cmd,
|
||||
goto cleanup;
|
||||
|
||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||
if (virCommandRun(cmd, NULL) < 0)
|
||||
if (virCommandRun(cmd, exitstatus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!outbuf) {
|
||||
@ -3114,7 +3116,8 @@ virCommandRunRegex(virCommandPtr cmd ATTRIBUTE_UNUSED,
|
||||
int *nvars ATTRIBUTE_UNUSED,
|
||||
virCommandRunRegexFunc func ATTRIBUTE_UNUSED,
|
||||
void *data ATTRIBUTE_UNUSED,
|
||||
const char *prefix ATTRIBUTE_UNUSED)
|
||||
const char *prefix ATTRIBUTE_UNUSED,
|
||||
int *exitstatus ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("%s not implemented on Win32"), __FUNCTION__);
|
||||
|
@ -205,7 +205,8 @@ int virCommandRunRegex(virCommandPtr cmd,
|
||||
int *nvars,
|
||||
virCommandRunRegexFunc func,
|
||||
void *data,
|
||||
const char *cmd_to_ignore);
|
||||
const char *cmd_to_ignore,
|
||||
int *exitstatus);
|
||||
|
||||
int virCommandRunNul(virCommandPtr cmd,
|
||||
size_t n_columns,
|
||||
|
@ -87,7 +87,7 @@ virISCSIGetSession(const char *devpath,
|
||||
regexes,
|
||||
vars,
|
||||
virISCSIExtractSession,
|
||||
&cbdata, NULL) < 0)
|
||||
&cbdata, NULL, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (cbdata.session == NULL && !probe) {
|
||||
@ -437,7 +437,7 @@ virISCSIScanTargets(const char *portal,
|
||||
regexes,
|
||||
vars,
|
||||
virISCSIGetTargets,
|
||||
&list, NULL) < 0)
|
||||
&list, NULL, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < list.ntargets; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user