diff --git a/src/libsysprof-profile/sysprof-recording.c b/src/libsysprof-profile/sysprof-recording.c index 24c9c7b5..c16e1808 100644 --- a/src/libsysprof-profile/sysprof-recording.c +++ b/src/libsysprof-profile/sysprof-recording.c @@ -226,6 +226,47 @@ sysprof_recording_fiber (gpointer user_data) add_metadata (self, "HOSTTYPE", g_getenv ("HOSTTYPE")); add_metadata (self, "OSTYPE", g_getenv ("OSTYPE")); + /* Log information about the spawning process */ + if (self->spawnable != NULL) + { + const char * const *argv = sysprof_spawnable_get_argv (self->spawnable); + const char * const *env = sysprof_spawnable_get_environ (self->spawnable); + const char *cwd = sysprof_spawnable_get_cwd (self->spawnable); + + if (cwd) + add_metadata (self, "spawnable.cwd", cwd); + + if (env != NULL) + { + g_autoptr(GString) str = g_string_new (NULL); + + for (guint e = 0; env[e]; e++) + { + g_autofree char *quoted = g_shell_quote (env[e]); + + g_string_append (str, quoted); + g_string_append_c (str, ' '); + } + + add_metadata (self, "spawnable.environ", str->str); + } + + if (argv != NULL) + { + g_autoptr(GString) str = g_string_new (NULL); + + for (guint a = 0; argv[a]; a++) + { + g_autofree char *quoted = g_shell_quote (argv[a]); + + g_string_append (str, quoted); + g_string_append_c (str, ' '); + } + + add_metadata (self, "spawnable.argv", str->str); + } + } + /* Save a copy of os-release for troubleshooting */ dex_await (_sysprof_recording_add_file (self, "/etc/os-release", FALSE), NULL); diff --git a/src/libsysprof-profile/sysprof-spawnable.c b/src/libsysprof-profile/sysprof-spawnable.c index 4c9e0a56..6b4fe15c 100644 --- a/src/libsysprof-profile/sysprof-spawnable.c +++ b/src/libsysprof-profile/sysprof-spawnable.c @@ -320,17 +320,21 @@ sysprof_spawnable_spawn (SysprofSpawnable *self, return g_subprocess_launcher_spawnv (launcher, argv, error); } +const char * +sysprof_spawnable_get_cwd (SysprofSpawnable *self) +{ + g_return_val_if_fail (SYSPROF_IS_SPAWNABLE (self), NULL); + + return self->cwd; +} + void sysprof_spawnable_set_cwd (SysprofSpawnable *self, const gchar *cwd) { g_return_if_fail (SYSPROF_IS_SPAWNABLE (self)); - if (g_strcmp0 (cwd, self->cwd) != 0) - { - g_free (self->cwd); - self->cwd = g_strdup (cwd); - } + g_set_str (&self->cwd, cwd); } /** diff --git a/src/libsysprof-profile/sysprof-spawnable.h b/src/libsysprof-profile/sysprof-spawnable.h index 9f14b560..f427f8de 100644 --- a/src/libsysprof-profile/sysprof-spawnable.h +++ b/src/libsysprof-profile/sysprof-spawnable.h @@ -47,6 +47,8 @@ SYSPROF_AVAILABLE_IN_ALL void sysprof_spawnable_append_args (SysprofSpawnable *self, const char * const *argv); SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_spawnable_get_cwd (SysprofSpawnable *self); +SYSPROF_AVAILABLE_IN_ALL void sysprof_spawnable_set_cwd (SysprofSpawnable *self, const char *cwd); SYSPROF_AVAILABLE_IN_ALL