Hooks may now be used as filters.
{
VIR_INFO("Reloading configuration on SIGHUP");
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-",
- VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL);
+ VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL, NULL);
if (virStateReload() < 0)
VIR_WARN("Error while reloading drivers");
}
* an error ?
*/
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_START,
- 0, "start", NULL);
+ 0, "start", NULL, NULL);
if (daemonSetupNetworking(srv, config,
sock_file, sock_file_ro,
ret = 0;
virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_SHUTDOWN,
- 0, "shutdown", NULL);
+ 0, "shutdown", NULL, NULL);
cleanup:
virNetServerProgramFree(remoteProgram);
/* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
- VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END, NULL, xml);
+ VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END,
+ NULL, xml, NULL);
VIR_FREE(xml);
}
int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
- VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
+ VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN,
+ NULL, xml, NULL);
VIR_FREE(xml);
/*
int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
- VIR_HOOK_QEMU_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
+ VIR_HOOK_QEMU_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN,
+ NULL, xml, NULL);
VIR_FREE(xml);
/*
int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
- VIR_HOOK_QEMU_OP_START, VIR_HOOK_SUBOP_BEGIN, NULL, xml);
+ VIR_HOOK_QEMU_OP_START, VIR_HOOK_SUBOP_BEGIN,
+ NULL, xml, NULL);
VIR_FREE(xml);
/*
/* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
- VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END, NULL, xml);
+ VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END,
+ NULL, xml, NULL);
VIR_FREE(xml);
}
/* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
- VIR_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END, NULL, xml);
+ VIR_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END,
+ NULL, xml, NULL);
VIR_FREE(xml);
}
return(1);
}
-/*
+/**
* virHookCall:
* @driver: the driver number (from virHookDriver enum)
* @id: an id for the object '-' if non available for example on daemon hooks
* @sub_op: 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 hook call, where the external script for the driver is
* called with the given information. This is a synchronous call, we wait for
- * execution completion
+ * execution completion. If @output is non-NULL, *output is guaranteed to be
+ * allocated after successful virHookCall, and is best-effort allocated after
+ * failed virHookCall; the caller is responsible for freeing *output.
*
* Returns: 0 if the execution succeeded, 1 if the script was not found or
* invalid parameters, and -1 if script returned an error
*/
int
-virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
- const char *input) {
+virHookCall(int driver,
+ const char *id,
+ int op,
+ int sub_op,
+ const char *extra,
+ const char *input,
+ char **output)
+{
int ret;
int exitstatus;
char *path;
const char *opstr;
const char *subopstr;
+ if (output)
+ *output = NULL;
+
if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
(driver >= VIR_HOOK_DRIVER_LAST))
return(1);
if (input)
virCommandSetInputBuffer(cmd, input);
+ if (output)
+ virCommandSetOutputBuffer(cmd, output);
ret = virCommandRun(cmd, &exitstatus);
if (ret == 0 && exitstatus != 0) {
int virHookPresent(int driver);
int virHookCall(int driver, const char *id, int op, int sub_op,
- const char *extra, const char *input);
+ const char *extra, const char *input, char **output);
#endif /* __VIR_HOOKS_H__ */