From: mbuesch@freenet.de Date: Tue, 30 Dec 2003 09:21:06 +0000 (-0800) Subject: [PATCH] introduce signal handler X-Git-Tag: 012~17 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d12ecb53cf8c5955135b94e4b671ad28dfb3a7b4;p=systemd [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. --- diff --git a/udev.c b/udev.c index 71c5f1fb..1d66410b 100644 --- a/udev.c +++ b/udev.c @@ -28,6 +28,7 @@ #include #include #include +#include #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;