[sysprof] libsysprof: extend LD_PRELOAD when pre-existing



commit cd2c2c954ab9e54294ff4beae310ea5ceb52a8ba
Author: Christian Hergert <chergert redhat com>
Date:   Fri Feb 21 12:40:25 2020 -0800

    libsysprof: extend LD_PRELOAD when pre-existing

 src/libsysprof/sysprof-memprof-source.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/src/libsysprof/sysprof-memprof-source.c b/src/libsysprof/sysprof-memprof-source.c
index 00ffc9f..895a28a 100644
--- a/src/libsysprof/sysprof-memprof-source.c
+++ b/src/libsysprof/sysprof-memprof-source.c
@@ -36,11 +36,21 @@ sysprof_memprof_source_modify_spawn (SysprofSource    *source,
   g_assert (SYSPROF_IS_SOURCE (source));
   g_assert (SYSPROF_IS_SPAWNABLE (spawnable));
 
-#ifdef __linux__
   sysprof_spawnable_setenv (spawnable, "G_SLICE", "always-malloc");
-  sysprof_spawnable_setenv (spawnable,
-                            "LD_PRELOAD",
-                            PACKAGE_LIBEXECDIR"/libsysprof-memory-"API_VERSION_S".so");
+
+#ifdef __linux__
+  {
+    static const gchar so_path[] = PACKAGE_LIBEXECDIR"/libsysprof-memory-"API_VERSION_S".so";
+    g_autofree gchar *freeme = NULL;
+    const gchar *ld_preload;
+
+    if (!(ld_preload = sysprof_spawnable_getenv (spawnable, "LD_PRELOAD")))
+      sysprof_spawnable_setenv (spawnable, "LD_PRELOAD", so_path);
+    else
+      sysprof_spawnable_setenv (spawnable,
+                                "LD_PRELOAD",
+                                (freeme = g_strdup_printf ("%s:%s", so_path, ld_preload)));
+  }
 #endif
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]