libsysprof-profile: add ld_preload helper

This is to be used by instruments to adjust the spawnable to inject preload
into the spawned environment.
This commit is contained in:
Christian Hergert
2023-06-02 17:09:44 -07:00
parent 1a3facf6ff
commit 37ad704186
2 changed files with 19 additions and 0 deletions

View File

@ -378,3 +378,19 @@ sysprof_spawnable_add_trace_fd (SysprofSpawnable *self,
return g_steal_fd (&fd);
}
void
sysprof_spawnable_add_ld_preload (SysprofSpawnable *self,
const char *library_path)
{
g_autofree char *amended = NULL;
const char *val;
g_return_if_fail (SYSPROF_IS_SPAWNABLE (self));
g_return_if_fail (library_path != NULL);
if ((val = sysprof_spawnable_getenv (self, "LD_PRELOAD")))
library_path = amended = g_strdup_printf ("%s:%s", val, library_path);
sysprof_spawnable_setenv (self, "LD_PRELOAD", library_path);
}

View File

@ -78,6 +78,9 @@ SYSPROF_AVAILABLE_IN_ALL
int sysprof_spawnable_add_trace_fd (SysprofSpawnable *self,
const char *envvar);
SYSPROF_AVAILABLE_IN_ALL
void sysprof_spawnable_add_ld_preload (SysprofSpawnable *self,
const char *library_path);
SYSPROF_AVAILABLE_IN_ALL
GSubprocess *sysprof_spawnable_spawn (SysprofSpawnable *self,
GError **error);
SYSPROF_AVAILABLE_IN_ALL