]> git.sesse.net Git - vlc/blobdiff - src/misc/threads.c
Keep track of object held by threads
[vlc] / src / misc / threads.c
index 16f4987da0562045c5dffd00ad2c57d71f7a1f7f..33270df4a65a75be81a6d9ba63b24a761bea1df3 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include "libvlc.h"
 #include <assert.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#include <signal.h>
 
 #define VLC_THREADS_UNINITIALIZED  0
 #define VLC_THREADS_PENDING        1
@@ -82,6 +83,10 @@ static inline unsigned long vlc_threadid (void)
      return v.i;
 }
 
+#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE)
+# include <execinfo.h>
+#endif
+
 /*****************************************************************************
  * vlc_thread_fatal: Report an error from the threading layer
  *****************************************************************************
@@ -99,7 +104,7 @@ void vlc_pthread_fatal (const char *action, int error,
 #ifdef __GLIBC__
     /* Avoid the strerror_r() prototype brain damage in glibc */
     errno = error;
-    fprintf (stderr, " Error message: %m\n");
+    dprintf (2, " Error message: %m at:\n");
 #else
     char buf[1000];
     const char *msg;
@@ -117,9 +122,15 @@ void vlc_pthread_fatal (const char *action, int error,
             break;
     }
     fprintf (stderr, " Error message: %s\n", msg);
+    fflush (stderr);
+#endif
+
+#ifdef HAVE_BACKTRACE
+    void *stack[20];
+    int len = backtrace (stack, sizeof (stack) / sizeof (stack[0]));
+    backtrace_symbols_fd (stack, len, 2);
 #endif
 
-    fflush (stderr);
     abort ();
 }
 #else
@@ -471,7 +482,25 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
     vlc_mutex_lock( &p_this->object_lock );
 
 #if defined( LIBVLC_USE_PTHREAD )
+    sigset_t set, oldset;
+
+    /* We really don't want signals to (literaly) interrupt our blocking I/O
+     * system calls. SIGPIPE is especially bad, as it can be caused by remote
+     * peers through connected sockets. Generally, we cannot know which signals
+     * are handled by the main program. Also, external LibVLC bindings tend not
+     * to setup a proper signal mask before invoking LibVLC.
+     * Hence, we hereby block all signals, except those for which blocking is
+     * undefined, as listed below. Note that SIGKILL and SIGSTOP need not be
+     * listed (see the documentation for pthread_sigmask) here. */
+    sigfillset (&set);
+    sigdelset (&set, SIGFPE);
+    sigdelset (&set, SIGILL);
+    sigdelset (&set, SIGSEGV);
+    sigdelset (&set, SIGBUS);
+    pthread_sigmask (SIG_BLOCK, &set, &oldset);
+
     i_ret = pthread_create( &p_priv->thread_id, NULL, thread_entry, boot );
+    pthread_sigmask (SIG_SETMASK, &oldset, NULL);
 
 #ifndef __APPLE__
     if( config_GetInt( p_this, "rt-priority" ) > 0 )