提交 8b104947 编写于 作者: J John Ferlan

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.
上级 f6ececa6
...@@ -267,7 +267,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state) ...@@ -267,7 +267,7 @@ virStorageBackendFileSystemNetFindNFSPoolSources(virNetfsDiscoverState *state)
if (virCommandRunRegex(cmd, 1, regexes, vars, if (virCommandRunRegex(cmd, 1, regexes, vars,
virStorageBackendFileSystemNetFindPoolSourcesFunc, virStorageBackendFileSystemNetFindPoolSourcesFunc,
state, NULL) < 0) state, NULL, NULL) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
......
...@@ -398,7 +398,8 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, ...@@ -398,7 +398,8 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
vars, vars,
virStorageBackendLogicalMakeVol, virStorageBackendLogicalMakeVol,
&cbdata, &cbdata,
"lvs") < 0) "lvs",
NULL) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -511,10 +512,10 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList) ...@@ -511,10 +512,10 @@ virStorageBackendLogicalGetPoolSources(virStoragePoolSourceListPtr sourceList)
cmd = virCommandNewArgList(PVS, cmd = virCommandNewArgList(PVS,
"--noheadings", "--noheadings",
"-o", "pv_name,vg_name", "-o", "pv_name,vg_name",
NULL); NULL, NULL);
if (virCommandRunRegex(cmd, 1, regexes, vars, if (virCommandRunRegex(cmd, 1, regexes, vars,
virStorageBackendLogicalFindPoolSourcesFunc, virStorageBackendLogicalFindPoolSourcesFunc,
sourceList, "pvs") < 0) sourceList, "pvs", NULL) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
...@@ -799,7 +800,8 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -799,7 +800,8 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
vars, vars,
virStorageBackendLogicalRefreshPoolFunc, virStorageBackendLogicalRefreshPoolFunc,
pool, pool,
"vgs") < 0) "vgs",
NULL) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
......
...@@ -2900,6 +2900,7 @@ virCommandSetDryRun(virBufferPtr buf, ...@@ -2900,6 +2900,7 @@ virCommandSetDryRun(virBufferPtr buf,
* needs to return 0 on success * needs to return 0 on success
* @data: additional data that will be passed to the callback function * @data: additional data that will be passed to the callback function
* @prefix: prefix that will be skipped at the beginning of each line * @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. * Run an external program.
* *
...@@ -2917,7 +2918,8 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -2917,7 +2918,8 @@ virCommandRunRegex(virCommandPtr cmd,
int *nvars, int *nvars,
virCommandRunRegexFunc func, virCommandRunRegexFunc func,
void *data, void *data,
const char *prefix) const char *prefix,
int *exitstatus)
{ {
int err; int err;
regex_t *reg; regex_t *reg;
...@@ -2959,7 +2961,7 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -2959,7 +2961,7 @@ virCommandRunRegex(virCommandPtr cmd,
goto cleanup; goto cleanup;
virCommandSetOutputBuffer(cmd, &outbuf); virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, exitstatus) < 0)
goto cleanup; goto cleanup;
if (!outbuf) { if (!outbuf) {
...@@ -3114,7 +3116,8 @@ virCommandRunRegex(virCommandPtr cmd ATTRIBUTE_UNUSED, ...@@ -3114,7 +3116,8 @@ virCommandRunRegex(virCommandPtr cmd ATTRIBUTE_UNUSED,
int *nvars ATTRIBUTE_UNUSED, int *nvars ATTRIBUTE_UNUSED,
virCommandRunRegexFunc func ATTRIBUTE_UNUSED, virCommandRunRegexFunc func ATTRIBUTE_UNUSED,
void *data 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, virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s not implemented on Win32"), __FUNCTION__); _("%s not implemented on Win32"), __FUNCTION__);
......
...@@ -205,7 +205,8 @@ int virCommandRunRegex(virCommandPtr cmd, ...@@ -205,7 +205,8 @@ int virCommandRunRegex(virCommandPtr cmd,
int *nvars, int *nvars,
virCommandRunRegexFunc func, virCommandRunRegexFunc func,
void *data, void *data,
const char *cmd_to_ignore); const char *cmd_to_ignore,
int *exitstatus);
int virCommandRunNul(virCommandPtr cmd, int virCommandRunNul(virCommandPtr cmd,
size_t n_columns, size_t n_columns,
......
...@@ -87,7 +87,7 @@ virISCSIGetSession(const char *devpath, ...@@ -87,7 +87,7 @@ virISCSIGetSession(const char *devpath,
regexes, regexes,
vars, vars,
virISCSIExtractSession, virISCSIExtractSession,
&cbdata, NULL) < 0) &cbdata, NULL, NULL) < 0)
goto cleanup; goto cleanup;
if (cbdata.session == NULL && !probe) { if (cbdata.session == NULL && !probe) {
...@@ -437,7 +437,7 @@ virISCSIScanTargets(const char *portal, ...@@ -437,7 +437,7 @@ virISCSIScanTargets(const char *portal,
regexes, regexes,
vars, vars,
virISCSIGetTargets, virISCSIGetTargets,
&list, NULL) < 0) &list, NULL, NULL) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < list.ntargets; i++) { for (i = 0; i < list.ntargets; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册