From 4c8c92b7f6fabf7d785ca211f707fe75aed7cc6a Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 16 Aug 2011 19:31:02 +0200 Subject: [PATCH] lockfile.c: unlink locks on signal --- lockfile.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lockfile.c b/lockfile.c index a7b6654..b8258f3 100644 --- a/lockfile.c +++ b/lockfile.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,22 @@ static void remove_from_list(struct lockfile *lock) { } } +static void register_signal_handl(void (*handl)(int)) { + + signal(SIGINT, handl); + signal(SIGHUP, handl); + signal(SIGTERM, handl); + signal(SIGQUIT, handl); + signal(SIGPIPE, handl); +} + +static void sig_remove_from_list(int signo) { + + release_all_locks(); + signal(signo, SIG_DFL); + raise(signo); +} + static inline void init(void) { static int is_init = 0; @@ -73,6 +90,7 @@ static inline void init(void) { if (is_init) return; + register_signal_handl(sig_remove_from_list); atexit(release_all_locks); is_init = 1; }