For some reason init() seems to be called multiple times. Let's move the
initialization to the first ioctl().

Signed-off-by: Lionel Landwerlin <lionel.g.landwer...@intel.com>
---
 tools/aubdump.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/tools/aubdump.c b/tools/aubdump.c
index 30dc742..a2ac7f1 100644
--- a/tools/aubdump.c
+++ b/tools/aubdump.c
@@ -426,6 +426,32 @@ close(int fd)
        return libc_close(fd);
 }
 
+static void
+maybe_init(void)
+{
+       static bool initialized = false;
+       const char *args = getenv("INTEL_AUBDUMP_ARGS");
+
+       if (initialized)
+               return;
+
+       initialized = true;
+
+       if (sscanf(args, "verbose=%d;file=%m[^;];device=%i",
+                  &verbose, &filename, &device) != 3)
+               filename = strdup("intel.aub");
+       fail_if(filename == NULL, "intel_aubdump: out of memory\n");
+
+       if (device)
+               device_override = true;
+
+       bos = malloc(MAX_BO_COUNT * sizeof(bos[0]));
+       fail_if(bos == NULL, "intel_aubdump: out of memory\n");
+
+       file = fopen(filename, "w+");
+       fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", 
filename);
+}
+
 int
 ioctl(int fd, unsigned long request, ...)
 {
@@ -447,6 +473,8 @@ ioctl(int fd, unsigned long request, ...)
        }
 
        if (fd == drm_fd) {
+               maybe_init();
+
                switch (request) {
                case DRM_IOCTL_I915_GETPARAM: {
                        struct drm_i915_getparam *getparam = argp;
@@ -550,26 +578,10 @@ ioctl(int fd, unsigned long request, ...)
 static void
 init(void)
 {
-       const char *args = getenv("INTEL_AUBDUMP_ARGS");
-
        libc_close = dlsym(RTLD_NEXT, "close");
        libc_ioctl = dlsym(RTLD_NEXT, "ioctl");
        fail_if(libc_close == NULL || libc_ioctl == NULL,
                "intel_aubdump: failed to get libc ioctl or close\n");
-
-       if (sscanf(args, "verbose=%d;file=%m[^;];device=%i",
-                  &verbose, &filename, &device) != 3)
-               filename = strdup("intel.aub");
-       fail_if(filename == NULL, "intel_aubdump: out of memory\n");
-
-       if (device)
-               device_override = true;
-
-       bos = malloc(MAX_BO_COUNT * sizeof(bos[0]));
-       fail_if(bos == NULL, "intel_aubdump: out of memory\n");
-
-       file = fopen(filename, "w+");
-       fail_if(file == NULL, "intel_aubdump: failed to open file '%s'\n", 
filename);
 }
 
 static int
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to