diff options
-rw-r--r-- | util/cairo-trace/cairo-trace.in | 3 | ||||
-rw-r--r-- | util/cairo-trace/trace.c | 31 |
2 files changed, 21 insertions, 13 deletions
diff --git a/util/cairo-trace/cairo-trace.in b/util/cairo-trace/cairo-trace.in index 3e54d4ed..f2a5b8f5 100644 --- a/util/cairo-trace/cairo-trace.in +++ b/util/cairo-trace/cairo-trace.in @@ -85,7 +85,8 @@ if test $# -eq 0; then usage fi -#echo $* +CAIRO_TRACE_PROG_NAME="$1" +export CAIRO_TRACE_PROG_NAME LD_PRELOAD=@libdir@/cairo/cairo-trace.so export LD_PRELOAD diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c index f8275a69..3c47aafc 100644 --- a/util/cairo-trace/trace.c +++ b/util/cairo-trace/trace.c @@ -651,22 +651,29 @@ _trace_printf (const char *fmt, ...) static void get_prog_name (char *buf, int length) { - FILE *file = fopen ("/proc/self/cmdline", "rb"); - *buf = '\0'; - if (file != NULL) { - char *slash; + char *slash; + FILE *file; - slash = fgets (buf, length, file); - fclose (file); - if (slash == NULL) - return; + memset (buf, 0, length); + if (length == 0) + return; - slash = strrchr (buf, '/'); - if (slash != NULL) { - int len = strlen (slash+1); - memmove (buf, slash+1, len+1); + file = fopen ("/proc/self/cmdline", "rb"); + if (file != NULL) { + fgets (buf, length, file); + fclose (file); + } else { + char const *name = getenv ("CAIRO_TRACE_PROG_NAME"); + if (name != NULL) { + strncpy (buf, name, length-1); } } + + slash = strrchr (buf, '/'); + if (slash != NULL) { + size_t len = strlen (slash+1); + memmove (buf, slash+1, len+1); + } } static void |