diff options
author | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2010-07-15 18:09:14 +0000 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-02 04:14:44 +0200 |
commit | 5544c07aabea054590f70ece9af83636c698291c (patch) | |
tree | dbfef1a95dea822d95a38c8b601c23bec436a430 /stream | |
parent | 5ed772b9cddc4c0de6762e223428b3e36eceefff (diff) |
cache: Use sigaction() instead of signal()
Signal() has an 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).
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31738 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache2.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/stream/cache2.c b/stream/cache2.c index b492a17cd8..6e77cbcc7e 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -365,7 +365,8 @@ static void dummy_sighandler(int x) { 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)) { @@ -373,7 +374,8 @@ static void cache_mainloop(cache_vars_t *s) { // 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++; @@ -381,7 +383,8 @@ static void cache_mainloop(cache_vars_t *s) { } 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; |