From bbdeab659ca00996e624c7e9fbce692f4aa66503 Mon Sep 17 00:00:00 2001 From: sabetts Date: Sun, 11 Feb 2001 08:40:01 +0000 Subject: (set_sig_handler): Added (main): Uses set_sig_handler() instead of signal() --- src/main.c | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 7a00205..644ecd7 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -65,7 +66,7 @@ static struct option ratpoison_longopts[] = { {"help", no_argument, 0, 'h'}, static char ratpoison_opts[] = "hvrk"; void -sighandler () +sighandler (int signum) { fprintf (stderr, "ratpoison: Agg! I've been SHOT!\n"); clean_up (); @@ -73,7 +74,7 @@ sighandler () } void -hup_handler () +hup_handler (int signum) { /* Doesn't function correctly. The event IS placed on the queue but XSync() doesn't seem to sync it and until other events come in @@ -85,7 +86,7 @@ hup_handler () } void -alrm_handler () +alrm_handler (int signum) { int i; @@ -117,6 +118,36 @@ handler (Display *d, XErrorEvent *e) exit (EXIT_FAILURE); } +void +set_sig_handler (int sig, void (*action)(int)) +{ + /* use sigaction because SVR4 systems do not replace the signal + handler by default which is a tip of the hat to some god-aweful + ancient code. So use the POSIX sigaction call instead. */ + struct sigaction act; + + /* check setting for sig */ + if (sigaction (sig, NULL, &act)) + { + PRINT_ERROR ("Error %d fetching SIGALRM handler\n", errno ); + } + else + { + /* if the existing action is to ignore then leave it intact + otherwise add our handler */ + if (act.sa_handler != SIG_IGN) + { + act.sa_handler = action; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + if (sigaction (sig, &act, NULL)) + { + PRINT_ERROR ("Error %d setting SIGALRM handler\n", errno ); + } + } + } +} + void print_version () { @@ -186,10 +217,10 @@ main (int argc, char *argv[]) /* Setup signal handlers. */ XSetErrorHandler(handler); - if (signal (SIGALRM, alrm_handler) == SIG_IGN) signal (SIGALRM, SIG_IGN); - if (signal (SIGTERM, sighandler) == SIG_IGN) signal (SIGTERM, SIG_IGN); - if (signal (SIGINT, sighandler) == SIG_IGN) signal (SIGINT, SIG_IGN); - if (signal (SIGHUP, hup_handler) == SIG_IGN) signal (SIGHUP, SIG_IGN); + set_sig_handler (SIGALRM, alrm_handler); + set_sig_handler (SIGTERM, sighandler); + set_sig_handler (SIGINT, sighandler); + set_sig_handler (SIGHUP, hup_handler); /* Set ratpoison specific Atoms. */ rp_restart = XInternAtom (dpy, "RP_RESTART", False); -- cgit v1.2.3