void vlc_enable_override (void);
-static bool override = false;
-
-void vlc_enable_override (void)
-{
- override = true;
-}
-
#if defined (__GNUC__) /* typeof and statement-expression */ \
&& (defined (__ELF__) && !defined (__sun__))
/* Solaris crashes on printf("%s", NULL); which is legal, but annoying. */
# include <execinfo.h>
#endif
+static bool override = false;
+
+static void vlc_reset_override (void)
+{
+ override = false;
+}
+
+void vlc_enable_override (void)
+{
+ override = true;
+ pthread_atfork (NULL, NULL, vlc_reset_override);
+}
+
static void vlogbug (const char *level, const char *func, const char *fmt,
va_list ap)
{
}
-#endif /* __ELF__ */
+/*** Xlib ****/
+#ifdef HAVE_X11_XLIB_H
+# include <X11/Xlib.h>
+
+static pthread_mutex_t xlib_lock = PTHREAD_MUTEX_INITIALIZER;
+
+int (*XSetErrorHandler (int (*handler) (Display *, XErrorEvent *)))
+ (Display *, XErrorEvent *)
+{
+ if (override)
+ {
+ int (*ret) (Display *, XErrorEvent *);
+
+ pthread_mutex_lock (&xlib_lock);
+ LOG("Error", "%p", handler);
+ ret = CALL(XSetErrorHandler, handler);
+ pthread_mutex_unlock (&xlib_lock);
+ return ret;
+ }
+ return CALL(XSetErrorHandler, handler);
+}
+
+int (*XSetIOErrorHandler (int (*handler) (Display *))) (Display *)
+{
+ if (override)
+ {
+ int (*ret) (Display *);
+
+ pthread_mutex_lock (&xlib_lock);
+ LOG("Error", "%p", handler);
+ ret = CALL(XSetIOErrorHandler, handler);
+ pthread_mutex_unlock (&xlib_lock);
+ return ret;
+ }
+ return CALL(XSetIOErrorHandler, handler);
+}
+#endif
+#else
+static void vlc_enable_override (void)
+{
+}
+#endif