info: Replace %p and %r in GST_DEBUG_FILE

It's useful to be able to set a name pattern for GST_DEBUG_FILE so that
the same environment variable can be used for multiple processes and
still write to different files. Especially useful if these processes
run simultaneously.

%p: Replaced with PID
%r: Replaced with random number

%p is obviously useful. %r is useful when for instance running two
processes with same PID but in different containers.

https://bugzilla.gnome.org/show_bug.cgi?id=773092
This commit is contained in:
Stian Selnes 2015-10-29 22:51:18 +01:00 committed by Sebastian Dröge
parent fd728c2531
commit 287645c2d7

View file

@ -292,6 +292,33 @@ _priv_gst_in_valgrind (void)
return (in_valgrind == GST_VG_INSIDE);
}
static gchar *
_replace_pattern_in_gst_debug_file_name (gchar * name, const char * token, guint val)
{
gchar * token_start;
if ((token_start = strstr (name, token))) {
gsize token_len = strlen (token);
gchar * name_prefix = name;
gchar * name_suffix = token_start + token_len;
token_start[0] = '\0';
name = g_strdup_printf ("%s%u%s", name_prefix, val, name_suffix);
g_free (name_prefix);
}
return name;
}
static gchar *
_priv_gst_debug_file_name (const gchar * env)
{
gchar *name;
name = g_strdup (env);
name = _replace_pattern_in_gst_debug_file_name (name, "%p", getpid ());
name = _replace_pattern_in_gst_debug_file_name (name, "%r", g_random_int ());
return name;
}
/* Initialize the debugging system */
void
_priv_gst_debug_init (void)
@ -305,7 +332,9 @@ _priv_gst_debug_init (void)
if (strcmp (env, "-") == 0) {
log_file = stdout;
} else {
log_file = g_fopen (env, "w");
gchar *name = _priv_gst_debug_file_name (env);
log_file = g_fopen (name, "w");
g_free (name);
if (log_file == NULL) {
g_printerr ("Could not open log file '%s' for writing: %s\n", env,
g_strerror (errno));