diff --git a/gst/gstinfo.c b/gst/gstinfo.c index 75b5e4c7a7..ba2c407fa3 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -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));