diff options
author | mbuesch@freenet.de <mbuesch@freenet.de> | 2003-12-30 01:21:06 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:13:12 -0700 |
commit | d12ecb53cf8c5955135b94e4b671ad28dfb3a7b4 (patch) | |
tree | 8d6a9db1515c396259eae44de78fc0c31fcc91da /udev.c | |
parent | 8ed89229bc8afed84ad6d587a6df29329bbbf440 (diff) |
[PATCH] introduce signal handler
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.
Diffstat (limited to 'udev.c')
-rw-r--r-- | udev.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -28,6 +28,7 @@ #include <unistd.h> #include <errno.h> #include <ctype.h> +#include <signal.h> #include "udev.h" #include "udev_version.h" @@ -40,6 +41,22 @@ 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; |