]> err.no Git - systemd/commitdiff
[PATCH] introduce signal handler
authormbuesch@freenet.de <mbuesch@freenet.de>
Tue, 30 Dec 2003 09:21:06 +0000 (01:21 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:12 +0000 (21:13 -0700)
Here's a patch that adds a signal handler to udev to
clean up the environment (close the sysbus and close
the database) on kill-signals.

udev.c

diff --git a/udev.c b/udev.c
index 71c5f1fba538f33043495d231650722db7992e09..1d66410b6c0085ba1c9c780497fb4f8f94b98bc1 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,11 @@ int main(int argc, char **argv, char **envp)
        char *devpath;
        char *subsystem;
        int retval = -EINVAL;
-       
+
+       signal(SIGINT, sig_handler);
+       signal(SIGTERM, sig_handler);
+       signal(SIGKILL, sig_handler);
+
        main_argv = argv;
        main_envp = envp;