From: Gustavo Martin Morcuende Date: Wed, 16 Dec 2015 00:26:10 +0000 (+0100) Subject: From sig handler just call safe functions. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2FHEAD;p=JavaTCPFork%2F.git From sig handler just call safe functions. As long as you don't do what R.. user says in the comments below the answer you must use only safe functions. http://stackoverflow.com/questions/8833394/can-exit-fail-to-terminate-process/8833602#8833602 --- diff --git a/Daemon/javafork.c b/Daemon/javafork.c index 8ecb5e8..320d6f5 100644 --- a/Daemon/javafork.c +++ b/Daemon/javafork.c @@ -907,7 +907,15 @@ void sigint_handler(int sig) */ if (sigaction(SIGINT, &sigintAction, NULL) < 0) { syslog (LOG_ERR, "SIGINT restore signal handler failed: %m"); - exit (EXIT_FAILURE); + /* man 7 signal + * Async-signal-safe functions + * A signal handler function must be very careful, since processing elsewhere may be interrupted at some arbitrary + * point in the execution of the program. POSIX has the concept of "safe function". If a signal interrupts the + * execution of an unsafe function, and handler calls an unsafe function, then the behavior of the program is undefined. + * + * From sig handler I MAY USE JUST _exit + */ + _exit (EXIT_FAILURE); } kill(getpid(), SIGINT); }