chiark / gitweb /
[PATCH] move the signal handling registration to after we have initialized enough...
[elogind.git] / udev.c
diff --git a/udev.c b/udev.c
index ac29ec6f4424909fcd9799ec1db1fbeb3dc421ce..17eade221ec867a8420c56bc77f6b28c9c5f8a44 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <ctype.h>
+#include <signal.h>
 
 #include "udev.h"
 #include "udev_version.h"
 char **main_argv;
 char **main_envp;
 
+static void sig_handler(int signum)
+{
+       dbg("caught signal %d", signum);
+       switch (signum) {
+               case SIGINT:
+               case SIGTERM:
+               case SIGKILL:
+                       sysbus_disconnect();
+                       udevdb_exit();
+                       exit(20 + signum);
+                       break;
+               default:
+                       dbg("unhandled signal");
+       }
+}
+
 static inline char *get_action(void)
 {
        char *action;
@@ -70,7 +87,7 @@ int main(int argc, char **argv, char **envp)
        char *devpath;
        char *subsystem;
        int retval = -EINVAL;
-       
+
        main_argv = argv;
        main_envp = envp;
 
@@ -119,9 +136,14 @@ int main(int argc, char **argv, char **envp)
        retval = udevdb_init(UDEVDB_DEFAULT);
        if (retval != 0) {
                dbg("unable to initialize database");
-               goto exit;
+               goto exit_sysbus;
        }
 
+       /* set up a default signal handler for now */
+       signal(SIGINT, sig_handler);
+       signal(SIGTERM, sig_handler);
+       signal(SIGKILL, sig_handler);
+
        /* initialize the naming deamon */
        namedev_init();
 
@@ -137,6 +159,7 @@ int main(int argc, char **argv, char **envp)
        }
        udevdb_exit();
 
+exit_sysbus:
        /* disconnect from the system message bus */
        sysbus_disconnect();