diff options
Diffstat (limited to 'src/sigs.c')
-rw-r--r-- | src/sigs.c | 73 |
1 files changed, 34 insertions, 39 deletions
@@ -1,7 +1,7 @@ /* * Calcurse - text-based organizer * - * Copyright (c) 2004-2011 calcurse Development Team <misc@calcurse.org> + * Copyright (c) 2004-2012 calcurse Development Team <misc@calcurse.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,63 +43,58 @@ #include "calcurse.h" +#ifndef WAIT_MYPGRP +#define WAIT_MYPGRP 0 +#endif + /* * General signal handling routine. * Catch return values from children (user-defined notification commands). * This is needed to avoid zombie processes running on system. * Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically. */ -static void -generic_hdlr (int sig) +static void generic_hdlr(int sig) { - switch (sig) - { - case SIGCHLD: - while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0) - ; - break; - case SIGWINCH: - resize = 1; - clearok (curscr, TRUE); - (void)ungetch (KEY_RESIZE); - break; - case SIGTERM: - if (unlink (path_cpid) != 0) - { - EXIT (_("Could not remove calcurse lock file: %s\n"), - strerror (errno)); - } - exit (EXIT_SUCCESS); - break; + switch (sig) { + case SIGCHLD: + while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) ; + break; + case SIGWINCH: + resize = 1; + clearok(curscr, TRUE); + ungetch(KEY_RESIZE); + break; + case SIGTERM: + if (unlink(path_cpid) != 0) { + EXIT(_("Could not remove calcurse lock file: %s\n"), strerror(errno)); } + exit(EXIT_SUCCESS); + break; + } } -unsigned -sigs_set_hdlr (int sig, void (*handler)(int)) +unsigned sigs_set_hdlr(int sig, void (*handler) (int)) { struct sigaction sa; - memset (&sa, 0, sizeof sa); - sigemptyset (&sa.sa_mask); + memset(&sa, 0, sizeof sa); + sigemptyset(&sa.sa_mask); sa.sa_handler = handler; sa.sa_flags = 0; - if (sigaction (sig, &sa, (struct sigaction *)0) == -1) - { - ERROR_MSG (_("Error setting signal #%d : %s\n"), - sig, strerror (errno)); - return 0; - } + if (sigaction(sig, &sa, NULL) == -1) { + ERROR_MSG(_("Error setting signal #%d : %s\n"), sig, strerror(errno)); + return 0; + } return 1; } /* Signal handling init. */ -void -sigs_init () +void sigs_init() { - if (!sigs_set_hdlr (SIGCHLD, generic_hdlr) - || !sigs_set_hdlr (SIGWINCH, generic_hdlr) - || !sigs_set_hdlr (SIGTERM, generic_hdlr) - || !sigs_set_hdlr (SIGINT, SIG_IGN)) - exit_calcurse (1); + if (!sigs_set_hdlr(SIGCHLD, generic_hdlr) + || !sigs_set_hdlr(SIGWINCH, generic_hdlr) + || !sigs_set_hdlr(SIGTERM, generic_hdlr) + || !sigs_set_hdlr(SIGINT, SIG_IGN)) + exit_calcurse(1); } |