Mercurial > mplayer.hg
comparison stream/cache2.c @ 31672:61eac0d05f20
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).
author | reimar |
---|---|
date | Thu, 15 Jul 2010 18:09:14 +0000 |
parents | 9ce59b78dbfd |
children | ba740e64ba01 |
comparison
equal
deleted
inserted
replaced
31671:4541f1921482 | 31672:61eac0d05f20 |
---|---|
364 * Main loop of the cache process or thread. | 364 * Main loop of the cache process or thread. |
365 */ | 365 */ |
366 static void cache_mainloop(cache_vars_t *s) { | 366 static void cache_mainloop(cache_vars_t *s) { |
367 int sleep_count = 0; | 367 int sleep_count = 0; |
368 #if FORKED_CACHE | 368 #if FORKED_CACHE |
369 signal(SIGUSR1, SIG_IGN); | 369 struct sigaction sa = { .sa_handler = SIG_IGN }; |
370 sigaction(SIGUSR1, &sa, NULL); | |
370 #endif | 371 #endif |
371 do { | 372 do { |
372 if (!cache_fill(s)) { | 373 if (!cache_fill(s)) { |
373 #if FORKED_CACHE | 374 #if FORKED_CACHE |
374 // Let signal wake us up, we cannot leave this | 375 // Let signal wake us up, we cannot leave this |
375 // enabled since we do not handle EINTR in most places. | 376 // enabled since we do not handle EINTR in most places. |
376 // This might need extra code to work on BSD. | 377 // This might need extra code to work on BSD. |
377 signal(SIGUSR1, dummy_sighandler); | 378 sa.sa_handler = dummy_sighandler; |
379 sigaction(SIGUSR1, &sa, NULL); | |
378 #endif | 380 #endif |
379 if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { | 381 if (sleep_count < INITIAL_FILL_USLEEP_COUNT) { |
380 sleep_count++; | 382 sleep_count++; |
381 usec_sleep(INITIAL_FILL_USLEEP_TIME); | 383 usec_sleep(INITIAL_FILL_USLEEP_TIME); |
382 } else | 384 } else |
383 usec_sleep(FILL_USLEEP_TIME); // idle | 385 usec_sleep(FILL_USLEEP_TIME); // idle |
384 #if FORKED_CACHE | 386 #if FORKED_CACHE |
385 signal(SIGUSR1, SIG_IGN); | 387 sa.sa_handler = SIG_IGN; |
388 sigaction(SIGUSR1, &sa, NULL); | |
386 #endif | 389 #endif |
387 } else | 390 } else |
388 sleep_count = 0; | 391 sleep_count = 0; |
389 // cache_stats(s->cache_data); | 392 // cache_stats(s->cache_data); |
390 } while (cache_execute_control(s)); | 393 } while (cache_execute_control(s)); |