# HG changeset patch # User reimar # Date 1279217354 0 # Node ID 61eac0d05f20baa3d5247df41be868de0a93ddd5 # Parent 4541f19214826f1bd7d700ddf1dabe06ca5b3c0f Use sigaction() instead of signal(), the latter has a unavoidable race-condition on "broken by backwards-compatibility" systems like Solaris. (upon receiving a signal, the handler is reset to SIG_DFL, thus a second signal will kill the process, the problem could also be reduced by re-installing the handler inside the handler, but there's still a race-condition and the risk of the handler being called inside the handler). diff -r 4541f1921482 -r 61eac0d05f20 stream/cache2.c --- a/stream/cache2.c Thu Jul 15 17:59:46 2010 +0000 +++ b/stream/cache2.c Thu Jul 15 18:09:14 2010 +0000 @@ -366,7 +366,8 @@ static void cache_mainloop(cache_vars_t *s) { int sleep_count = 0; #if FORKED_CACHE - signal(SIGUSR1, SIG_IGN); + struct sigaction sa = { .sa_handler = SIG_IGN }; + sigaction(SIGUSR1, &sa, NULL); #endif do { if (!cache_fill(s)) { @@ -374,7 +375,8 @@ // Let signal wake us up, we cannot leave this // enabled since we do not handle EINTR in most places. // This might need extra code to work on BSD. - signal(SIGUSR1, dummy_sighandler); + sa.sa_handler = dummy_sighandler; + sigaction(SIGUSR1, &sa, NULL); #endif if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { sleep_count++; @@ -382,7 +384,8 @@ } else usec_sleep(FILL_USLEEP_TIME); // idle #if FORKED_CACHE - signal(SIGUSR1, SIG_IGN); + sa.sa_handler = SIG_IGN; + sigaction(SIGUSR1, &sa, NULL); #endif } else sleep_count = 0;