]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add the script hook support to the libvirt daemon
authorDaniel Veillard <veillard@redhat.com>
Fri, 26 Mar 2010 14:53:32 +0000 (15:53 +0100)
committerDaniel Veillard <veillard@redhat.com>
Mon, 29 Mar 2010 16:21:04 +0000 (18:21 +0200)
It supports 3 kind of probing times, at daemon startup, when the
daemon reloads its drivers on SIGHUP and when the daemon exits

* daemon/libvirtd.c: daemon hooks for startup, reload and exit

daemon/libvirtd.c

index bd45016bff72dbd5347b6a2d4601101932cba229..4bdf4e261d4a232ab92f561f360638e67da819e3 100644 (file)
@@ -62,6 +62,7 @@
 #include "event.h"
 #include "memory.h"
 #include "stream.h"
+#include "hooks.h"
 #ifdef HAVE_AVAHI
 # include "mdns.h"
 #endif
@@ -199,6 +200,7 @@ enum {
     VIR_DAEMON_ERR_PRIVS,
     VIR_DAEMON_ERR_NETWORK,
     VIR_DAEMON_ERR_CONFIG,
+    VIR_DAEMON_ERR_HOOKS,
 
     VIR_DAEMON_ERR_LAST
 };
@@ -212,7 +214,8 @@ VIR_ENUM_IMPL(virDaemonErr, VIR_DAEMON_ERR_LAST,
               "Unable to setup signal handlers",
               "Unable to drop privileges",
               "Unable to initialize network sockets",
-              "Unable to load configuration file")
+              "Unable to load configuration file",
+              "Unable to look for hook scripts")
 
 static void sig_handler(int sig, siginfo_t * siginfo,
                         void* context ATTRIBUTE_UNUSED) {
@@ -378,8 +381,11 @@ qemudDispatchSignalEvent(int watch ATTRIBUTE_UNUSED,
     switch (siginfo.si_signo) {
     case SIGHUP:
         VIR_INFO0(_("Reloading configuration on SIGHUP"));
+        virHookCall(VIR_HOOK_DRIVER_DAEMON, "-",
+                    VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL);
         if (virStateReload() < 0)
             VIR_WARN0(_("Error while reloading drivers"));
+
         break;
 
     case SIGINT:
@@ -3143,9 +3149,23 @@ int main(int argc, char **argv) {
         goto error;
     }
 
+    /* setup the hooks if any */
+    if (virHookInitialize()) {
+        ret = VIR_DAEMON_ERR_HOOKS;
+        goto error;
+    }
+
     /* Disable error func, now logging is setup */
     virSetErrorFunc(NULL, virshErrorHandler);
 
+    /*
+     * Call the daemon startup hook
+     * TODO: should we abort the daemon startup if the script returned
+     *       an error ?
+     */
+    virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_START,
+                0, "start", NULL);
+
     if (qemudNetworkInit(server) < 0) {
         ret = VIR_DAEMON_ERR_NETWORK;
         goto error;
@@ -3206,6 +3226,9 @@ shutdown:
     }
     pthread_join(server->eventThread, NULL);
 
+    virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_SHUTDOWN,
+                0, "shutdown", NULL);
+
 error:
     if (statuswrite != -1) {
         if (ret != 0) {