mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2025-12-24 19:30:10 +01:00
[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.
This commit is contained in:
parent
17cdffafda
commit
c64f6f8a15
2 changed files with 21 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
char *slash;
|
||||
FILE *file;
|
||||
|
||||
memset (buf, 0, length);
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
file = fopen ("/proc/self/cmdline", "rb");
|
||||
if (file != NULL) {
|
||||
char *slash;
|
||||
|
||||
slash = fgets (buf, length, file);
|
||||
fgets (buf, length, file);
|
||||
fclose (file);
|
||||
if (slash == NULL)
|
||||
return;
|
||||
|
||||
slash = strrchr (buf, '/');
|
||||
if (slash != NULL) {
|
||||
int len = strlen (slash+1);
|
||||
memmove (buf, slash+1, len+1);
|
||||
} 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue