summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2009-06-26 16:54:11 +0300
committerM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>2009-09-02 04:42:07 +0100
commitc64f6f8a15306cdcf5dd02480049b0f9112fd6ac (patch)
treeb7463bcca964f2216c0ef36fd2275d2ac38caee4
parent17cdffafda04514f08e0f0f11d0a85b938282c38 (diff)
[trace] Get the tracee program name from the environment.
Support non-Linux systems which don't have a /proc/self/cmdline by transferring the application name given to cairo-trace via an environment variable CAIRO_TRACE_PROG_NAME.
-rw-r--r--util/cairo-trace/cairo-trace.in3
-rw-r--r--util/cairo-trace/trace.c31
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