summaryrefslogtreecommitdiff
path: root/src/signal.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-29 06:13:48 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-29 06:13:48 +0000
commitd759331ef32bbf0908bce4d8753293ef08bbbfed (patch)
tree67e33b5fe11e14d154beaa6bf609aebac760645c /src/signal.c
parentadded -O2 to CCFLAGS (diff)
improved signal handling
Diffstat (limited to 'src/signal.c')
-rw-r--r--src/signal.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/signal.c b/src/signal.c
index 1086969..122577d 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -42,10 +42,9 @@ volatile sig_atomic_t signal_exit = 0;
void signal_init()
{
- signal(SIGINT, handle_signal_exit);
- signal(SIGQUIT, handle_signal_exit);
- signal(SIGTERM, handle_signal_exit);
-
+ signal(SIGINT, handle_signal);
+ signal(SIGQUIT, handle_signal);
+ signal(SIGTERM, handle_signal);
signal(SIGHUP, handle_signal);
signal(SIGUSR1, handle_signal);
signal(SIGUSR2, handle_signal);
@@ -54,29 +53,12 @@ void signal_init()
void handle_signal(int sig)
{
switch(sig) {
+ case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); signal_exit = 1; break;
+ case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); signal_exit = 1; break;
+ case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); signal_exit = 1; break;
case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); break;
case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); break;
case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); break;
default: log_printf(NOTICE, "Signal %d caught, ignoring", sig); break;
}
}
-
-void handle_signal_exit(int sig)
-{
- switch(sig) {
- case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); break;
- case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); break;
- case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); break;
- default: log_printf(NOTICE, "Signal %d caught, ignoring", sig); return;
- }
-
- if (signal_exit)
- raise (sig);
- signal_exit = 1;
-
- // do cleanup here
-
- signal (sig, SIG_DFL);
- raise (sig);
-}
-