-
-/*****************************************************************************
- * SigHandler: system signal handler
- *****************************************************************************
- * This thread receives all handled signals synchronously.
- * It tries to end the program in a clean way.
- *****************************************************************************/
-static void *SigHandler (void *data)
-{
- const sigset_t *exitset = (sigset_t *)data;
- sigset_t fullset;
- time_t abort_time = 0;
-
- pthread_sigmask (SIG_BLOCK, exitset, &fullset);
-
- for (;;)
- {
- int i_signal, state;
- if( sigwait (&fullset, &i_signal) != 0 )
- continue;
-
-#ifdef __APPLE__
- /* In Mac OS X up to 10.4.8 sigwait (among others) is not a pthread
- * cancellation point */
- pthread_testcancel();
-#endif
-
- if (!sigismember (exitset, i_signal))
- continue; /* Ignore "dummy" signals */
-
- /* Once a signal has been trapped, the termination sequence will be
- * armed and subsequent signals will be ignored to avoid sending
- * signals to a libvlc structure having been destroyed */
-
- pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state);
- if (abort_time == 0 || time (NULL) > abort_time)
- {
- time (&abort_time);
- abort_time += 2;
-
- fprintf (stderr, "signal %d received, terminating vlc - do it "
- "again quickly in case it gets stuck\n", i_signal);
- //VLC_Die( 0 );
- }
- else /* time (NULL) <= abort_time */
- {
- /* If user asks again more than 2 seconds later, die badly */
- pthread_sigmask (SIG_UNBLOCK, exitset, NULL);
- fprintf (stderr, "user insisted too much, dying badly\n");
-#ifdef __APPLE__
- /* On Mac OS X, use exit(-1) as it doesn't trigger
- * backtrace generation, whereas abort() does.
- * The backtrace generation trigger a Crash Dialog
- * And takes way too much time, which is not what
- * we want. */
- exit (-1);
-#else
- abort ();
-#endif
- }
- pthread_setcancelstate (state, NULL);
- }
- /* Never reached */
-}