X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bin%2Foverride.c;h=2e8919925b02828a00cb47d8b014e39589c28eb9;hb=18cc244e3c9d9a9dce053b2994c3025bf430d44a;hp=2f7606ba56367fc9964afced6a24a1f50c894700;hpb=4213a133fd1ef14fd9b62620412a45af091d73ae;p=vlc diff --git a/bin/override.c b/bin/override.c index 2f7606ba56..2e8919925b 100644 --- a/bin/override.c +++ b/bin/override.c @@ -26,13 +26,6 @@ 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. */ @@ -42,14 +35,43 @@ void vlc_enable_override (void) #include #include #include +#ifdef HAVE_EXECINFO_H +# include +#endif +#ifdef NDEBUG +# undef HAVE_BACKTRACE +#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) { +#ifdef HAVE_BACKTRACE + const size_t framec = 4; + void *framev[framec]; + + backtrace (framev, framec); +#endif flockfile (stderr); fprintf (stderr, "%s: call to %s(", level, func); vfprintf (stderr, fmt, ap); fputs (")\n", stderr); + fflush (stderr); +#ifdef HAVE_BACKTRACE + backtrace_symbols_fd (framev + 2, framec - 2, fileno (stderr)); +#endif funlockfile (stderr); } @@ -147,4 +169,71 @@ int rand (void) } -#endif /* __ELF__ */ +/** Signals **/ +#include + +void (*signal (int signum, void (*handler) (int))) (int) +{ + if (override) + { + const char *msg = "Error"; + + if ((signum == SIGPIPE && handler == SIG_IGN) + || (signum != SIGPIPE && handler == SIG_DFL)) + /* Same settings we already use */ + msg = "Warning"; + LOG(msg, "%d, %p", signum, handler); + } + return CALL(signal, signum, handler); +} + +int sigaction (int signum, const struct sigaction *act, struct sigaction *old) +{ + if (act != NULL) + LOG("Error", "%d, %p, %p", signum, act, old); + return CALL(sigaction, signum, act, old); +} + + +/*** Xlib ****/ +#ifdef HAVE_X11_XLIB_H +# include + +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 +void vlc_enable_override (void) +{ +} +#endif