提交 841910b5 编写于 作者: D Dmitry Nesterenko 提交者: Michal Privoznik

virhook: Separate hook script invocation into a function

This refactor is needed to support support hooks placed in
several files.
Signed-off-by: NDmitry Nesterenko <dmitry.nesterenko@virtuozzo.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 5a333b10
......@@ -221,6 +221,57 @@ virHookPresent(int driver)
return 1;
}
/**
* virRunScript:
* @path: the script path
* @id: an id for the object '-' if non available for example on daemon hooks
* @op: the operation on the id
* @subop: a sub_operation, currently unused
* @extra: optional string information
* @input: extra input given to the script on stdin
* @output: optional address of variable to store malloced result buffer
*
* Implement a execution of script. This is a synchronous call, we wait for
* execution completion. If @output is non-NULL, *output is guaranteed to be
* allocated after successful virRunScript, and is best-effort allocated after
* failed virRunScript; the caller is responsible for freeing *output.
*
* Returns: 0 if the execution succeeded, -1 if script returned an error
*/
static int
virRunScript(const char *path,
const char *id,
const char *op,
const char *subop,
const char *extra,
const char *input,
char **output)
{
int ret;
g_autoptr(virCommand) cmd = NULL;
VIR_DEBUG("Calling hook %s id=%s op=%s subop=%s extra=%s",
path, id, op, subop, extra);
cmd = virCommandNewArgList(path, id, op, subop, extra, NULL);
virCommandAddEnvPassCommon(cmd);
if (input)
virCommandSetInputBuffer(cmd, input);
if (output)
virCommandSetOutputBuffer(cmd, output);
ret = virCommandRun(cmd, NULL);
if (ret < 0) {
/* Convert INTERNAL_ERROR into known error. */
virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",
virGetLastErrorMessage());
}
return ret;
}
/**
* virHookCall:
* @driver: the driver number (from virHookDriver enum)
......@@ -249,7 +300,6 @@ virHookCall(int driver,
const char *input,
char **output)
{
int ret;
g_autofree char *path = NULL;
g_autoptr(virCommand) cmd = NULL;
const char *drvstr;
......@@ -318,24 +368,6 @@ virHookCall(int driver,
return -1;
}
VIR_DEBUG("Calling hook opstr=%s subopstr=%s extra=%s",
opstr, subopstr, extra);
cmd = virCommandNewArgList(path, id, opstr, subopstr, extra, NULL);
virCommandAddEnvPassCommon(cmd);
if (input)
virCommandSetInputBuffer(cmd, input);
if (output)
virCommandSetOutputBuffer(cmd, output);
ret = virCommandRun(cmd, NULL);
if (ret < 0) {
/* Convert INTERNAL_ERROR into known error. */
virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",
virGetLastErrorMessage());
}
return ret;
return virRunScript(path, id, opstr, subopstr, extra,
input, output);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册