From 1f43677f895a88ae880b35f9b18cc7e6869d0ca6 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 6 Oct 2016 15:30:24 +0100 Subject: tools: intel_aubdump: pass configuration through file descriptor This makes parsing options less complicated and easier to extend. v2: Fix device id parsing (atoi -> sscanf) (Sirisha) Combine with previous commit moving init function (Sirisha) v3: Fix behavior change between bash 4.3 & 4.4 in <<< with \n characters (Lionel) Signed-off-by: Lionel Landwerlin Reviewed-by: Sirisha Gandikota --- tools/aubdump.c | 58 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'tools/aubdump.c') diff --git a/tools/aubdump.c b/tools/aubdump.c index 30dc742f..f2cd2c1b 100644 --- a/tools/aubdump.c +++ b/tools/aubdump.c @@ -426,6 +426,46 @@ close(int fd) return libc_close(fd); } +static void +maybe_init(void) +{ + static bool initialized = false; + FILE *config; + char *key, *value; + + if (initialized) + return; + + initialized = true; + + config = fdopen(3, "r"); + while (fscanf(config, "%m[^=]=%m[^\n]\n", &key, &value) != EOF) { + if (!strcmp(key, "verbose")) { + verbose = 1; + } else if (!strcmp(key, "device")) { + fail_if(sscanf(value, "%i", &device) != 1, + "intel_aubdump: failed to parse device id '%s'", + value); + device_override = true; + } else if (!strcmp(key, "file")) { + filename = value; + file = fopen(filename, "w+"); + fail_if(file == NULL, + "intel_aubdump: failed to open file '%s'\n", + filename); + } else { + fprintf(stderr, "intel_aubdump: unknown option '%s'\n", key); + } + + free(key); + free(value); + } + fclose(config); + + bos = malloc(MAX_BO_COUNT * sizeof(bos[0])); + fail_if(bos == NULL, "intel_aubdump: out of memory\n"); +} + int ioctl(int fd, unsigned long request, ...) { @@ -447,6 +487,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 +592,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 -- cgit v1.2.3