Philip Martin wrote on Mon, Feb 08, 2016 at 10:33:05 +0000: > When there are two different signals I don't think there is a 'correct' > signal with which to exit, all that matters is that we exit with one of > the signals.
Agreed. > So how about: > > int saved_signum = signum_cancelled; > apr_signal(saved_signum, SIG_DFL); > kill(getpid(), saved_signum); This fixes the race I mentioned, but I think we have another problem here: signum_cancelled is accessed by the signal handler so it must be of type 'static volatile sig_atomic_t' (C89 §4.7.1.1)... but I don't think anything guarantees that signal numbers are representable as a sig_atomic_t. On Linux/amd64 and FreeBSD they are, but that need not be the case everywhere. If we can't assume sig_atomic_t is at least as large as an int, I think we have to use the following roundabout method: static volatile sig_atomic_t signum_cancelled[4] = {0, 0, 0, 0}; static void signal_handler(int signum) { ⋮ if (signum == SIGINT) signum_cancelled[0] = TRUE; #ifdef SIGHUP if (signum == SIGHUP) signum_cancelled[1] = TRUE; #endif #ifdef SIGTERM if (signum == SIGTERM) signum_cancelled[2] = TRUE; #endif #ifdef SIGBREAK if (signum == SIGBREAK) signum_cancelled[3] = TRUE; #endif } and then check which element(s) of the array are set to know which signal to send to self. Cheers, Daniel