From 4a8da40fc089d465b72ecee89e24cd92e6714669 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 23 Jan 2014 11:03:53 -0800 Subject: [PATCH] dri: Fix the logger error message handling. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since the loader changes, there has been a compiler warning that the prototype didn't match. It turns out that if a loader error message was ever thrown, you'd segfault because of trying to use the warning level as a format string. Reviewed-by: Keith Packard Tested-by: Keith Packard Reviewed-by: Kristian Høgsberg --- src/glx/dri3_glx.c | 2 +- src/glx/dri_common.c | 25 +++++++++++++++++++++++++ src/glx/dri_common.h | 10 ++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index 3e829651c05..2a9f0b7353c 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -1803,7 +1803,7 @@ dri3_create_display(Display * dpy) pdp->base.destroyDisplay = dri3_destroy_display; pdp->base.createScreen = dri3_create_screen; - loader_set_logger(ErrorMessageF); + loader_set_logger(dri_message); i = 0; pdp->loader_extensions[i++] = &imageLoaderExtension.base; diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index b5058c97c6e..93c45ea7bbd 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -40,6 +40,7 @@ #include #include "glxclient.h" #include "dri_common.h" +#include "loader.h" #ifndef RTLD_NOW #define RTLD_NOW 0 @@ -48,6 +49,30 @@ #define RTLD_GLOBAL 0 #endif +_X_HIDDEN void +dri_message(int level, const char *f, ...) +{ + va_list args; + int threshold = _LOADER_WARNING; + const char *libgl_debug; + + libgl_debug = getenv("LIBGL_DEBUG"); + if (libgl_debug) { + if (strstr(libgl_debug, "quiet")) + threshold = _LOADER_FATAL; + else if (strstr(libgl_debug, "verbose")) + threshold = _LOADER_DEBUG; + } + + /* Note that the _LOADER_* levels are lower numbers for more severe. */ + if (level <= threshold) { + fprintf(stderr, "libGL%s: ", level <= _LOADER_WARNING ? " error" : ""); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + } +} + /** * Print informational message to stderr if LIBGL_DEBUG is set to * "verbose". diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h index 4fe0d3faf98..425d89f9224 100644 --- a/src/glx/dri_common.h +++ b/src/glx/dri_common.h @@ -39,6 +39,12 @@ #include #include +#if (__GNUC__ >= 3) +#define PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a))) +#else +#define PRINTFLIKE(f, a) +#endif + typedef struct __GLXDRIconfigPrivateRec __GLXDRIconfigPrivate; struct __GLXDRIconfigPrivateRec @@ -61,10 +67,10 @@ driReleaseDrawables(struct glx_context *gc); extern const __DRIsystemTimeExtension systemTimeExtension; -extern void InfoMessageF(const char *f, ...); +extern void dri_message(int level, const char *f, ...) PRINTFLIKE(2, 3); +extern void InfoMessageF(const char *f, ...); extern void ErrorMessageF(const char *f, ...); - extern void CriticalErrorMessageF(const char *f, ...); extern void *driOpenDriver(const char *driverName); -- 2.30.2