diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c index 80c62c58..9fa940a9 100644 --- a/nouveau/nouveau.c +++ b/nouveau/nouveau.c @@ -46,15 +46,33 @@ #include "nvif/ioctl.h" #include "nvif/unpack.h" +drm_private FILE *nouveau_out = NULL; drm_private uint32_t nouveau_debug = 0; static void -debug_init(char *args) +debug_init(void) { - if (args) { - int n = strtol(args, NULL, 0); + static bool once = false; + char *debug, *out; + + if (once) + return; + once = true; + + debug = getenv("NOUVEAU_LIBDRM_DEBUG"); + if (debug) { + int n = strtol(debug, NULL, 0); if (n >= 0) nouveau_debug = n; + + } + + nouveau_out = stderr; + out = getenv("NOUVEAU_LIBDRM_OUT"); + if (out) { + FILE *fout = fopen(out, "w"); + if (fout) + nouveau_out = fout; } } @@ -325,7 +343,7 @@ nouveau_drm_new(int fd, struct nouveau_drm **pdrm) struct nouveau_drm *drm; drmVersionPtr ver; - debug_init(getenv("NOUVEAU_LIBDRM_DEBUG")); + debug_init(); if (!(drm = calloc(1, sizeof(*drm)))) return -ENOMEM; diff --git a/nouveau/private.h b/nouveau/private.h index 13cec3cd..55fe57d8 100644 --- a/nouveau/private.h +++ b/nouveau/private.h @@ -1,6 +1,8 @@ #ifndef __NOUVEAU_LIBDRM_PRIVATE_H__ #define __NOUVEAU_LIBDRM_PRIVATE_H__ +#include + #include #include #include @@ -10,12 +12,13 @@ #include "nouveau.h" drm_private extern uint32_t nouveau_debug; +drm_private extern FILE *nouveau_out; #define dbg_on(lvl) (nouveau_debug & (1 << lvl)) #define dbg(lvl, fmt, args...) do { \ if (dbg_on((lvl))) \ - fprintf(stderr, "nouveau: "fmt, ##args); \ + fprintf(nouveau_out, "nouveau: "fmt, ##args); \ } while(0) -#define err(fmt, args...) fprintf(stderr, "nouveau: "fmt, ##args) +#define err(fmt, args...) fprintf(nouveau_out, "nouveau: "fmt, ##args) struct nouveau_client_kref { struct drm_nouveau_gem_pushbuf_bo *kref;