]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hooks: Add support for capturing hook output
authorJiri Denemark <jdenemar@redhat.com>
Mon, 27 Feb 2012 16:06:22 +0000 (17:06 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 29 Feb 2012 11:27:12 +0000 (12:27 +0100)
Hooks may now be used as filters.

daemon/libvirtd.c
src/lxc/lxc_driver.c
src/qemu/qemu_process.c
src/util/hooks.c
src/util/hooks.h

index b1b542bb84d8cd2755b78839aed457d34d263a62..52e80fa5a71e282121b2d664e827e61c0d9d8be8 100644 (file)
@@ -1148,7 +1148,7 @@ static void daemonReloadHandler(virNetServerPtr srv ATTRIBUTE_UNUSED,
 {
         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");
 }
@@ -1571,7 +1571,7 @@ int main(int argc, char **argv) {
      *       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,
@@ -1604,7 +1604,7 @@ int main(int argc, char **argv) {
     ret = 0;
 
     virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_SHUTDOWN,
-                0, "shutdown", NULL);
+                0, "shutdown", NULL, NULL);
 
 cleanup:
     virNetServerProgramFree(remoteProgram);
index d77afcc4c2f7d64c8625a105ff97a65c621a15a7..d9cbd9e90f0e7fd18916fb2011a66767fd53a64f 100644 (file)
@@ -1115,7 +1115,8 @@ static void lxcVmCleanup(lxc_driver_t *driver,
 
         /* 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);
     }
 
@@ -1632,7 +1633,8 @@ lxcBuildControllerCmd(lxc_driver_t *driver,
         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);
 
         /*
index 41218de4fe25d4c71159d7a41336921a5a20dd63..36e5ce61240fcf785c0df1b8c670f40430a7fe3c 100644 (file)
@@ -3120,7 +3120,8 @@ int qemuProcessStart(virConnectPtr conn,
         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);
 
         /*
@@ -3305,7 +3306,8 @@ int qemuProcessStart(virConnectPtr conn,
         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);
 
         /*
@@ -3726,7 +3728,8 @@ void qemuProcessStop(struct qemud_driver *driver,
 
         /* 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);
     }
 
@@ -3819,7 +3822,8 @@ retry:
 
         /* 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);
     }
 
index 110a94b52f9c491120add7481071bca45399e54b..8c16a3a56d0d6b3757792cf8b2064c04b321fec1 100644 (file)
@@ -173,7 +173,7 @@ virHookPresent(int driver) {
     return(1);
 }
 
-/*
+/**
  * virHookCall:
  * @driver: the driver number (from virHookDriver enum)
  * @id: an id for the object '-' if non available for example on daemon hooks
@@ -181,17 +181,26 @@ virHookPresent(int driver) {
  * @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;
@@ -200,6 +209,9 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
     const char *opstr;
     const char *subopstr;
 
+    if (output)
+        *output = NULL;
+
     if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
         (driver >= VIR_HOOK_DRIVER_LAST))
         return(1);
@@ -257,6 +269,8 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
 
     if (input)
         virCommandSetInputBuffer(cmd, input);
+    if (output)
+        virCommandSetOutputBuffer(cmd, output);
 
     ret = virCommandRun(cmd, &exitstatus);
     if (ret == 0 && exitstatus != 0) {
index fd7411c677ea66529cf8f9267e164b01d11c0ee8..a53ac2c3006eea0f63a8e0cc9f8115a8a964d0f5 100644 (file)
@@ -72,6 +72,6 @@ int virHookInitialize(void);
 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__ */