]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: preserve the existing LD_PRELOAD
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 9 Oct 2024 15:26:25 +0000 (16:26 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 17 Oct 2024 13:35:10 +0000 (08:35 -0500)
In order for the sanitisers to work correctly, we need to LD_PRELOAD the
sanitizer shared library.

So drop the explicit unset(LD_PRELOAD) and instead prepend the existing
value to the LD_PRELOAD path that we construct.

Const annotate the other LD_PRELOAD instance, while we're here.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/179
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
testsuite/test-testsuite.c
testsuite/testsuite.c

index 3b84aaa709456190bc6d7d34f8a6b86a4360c4c5..eff911a78a55db0d05afca96227a0fdc89c4b3e1 100644 (file)
@@ -30,7 +30,7 @@ static noreturn int testsuite_uname(const struct test *t)
                exit(EXIT_FAILURE);
 
        if (!streq(u.release, TEST_UNAME)) {
-               char *ldpreload = getenv("LD_PRELOAD");
+               const char *ldpreload = getenv("LD_PRELOAD");
                ERR("u.release=%s should be %s\n", u.release, TEST_UNAME);
                ERR("LD_PRELOAD=%s\n", ldpreload);
                exit(EXIT_FAILURE);
index 6e9d2089d508521cd59cd284b7841bbce66be22d..e12426a52a9c6eb4761d2346135703823139a958 100644 (file)
@@ -161,8 +161,6 @@ static void test_export_environ(const struct test *t)
        size_t i;
        const struct keyval *env;
 
-       unsetenv("LD_PRELOAD");
-
        for (i = 0; i < _TC_LAST; i++) {
                const char *ldpreload;
                size_t ldpreloadlen;
@@ -189,8 +187,27 @@ static void test_export_environ(const struct test *t)
                preload[preloadlen] = '\0';
        }
 
-       if (preload != NULL)
+       if (preload != NULL) {
+               const char *existing_preload = getenv("LD_PRELOAD");
+               if (existing_preload) {
+                       char *tmp;
+                       size_t len = strlen(existing_preload);
+
+                       tmp = malloc(preloadlen + 2 + len);
+                       if (tmp == NULL) {
+                               ERR("oom: test_export_environ()\n");
+                               return;
+                       }
+                       memcpy(tmp, existing_preload, len);
+                       tmp[len++] = ' ';
+                       memcpy(tmp + len, preload, preloadlen);
+                       preloadlen += len;
+                       tmp[preloadlen] = '\0';
+                       free(preload);
+                       preload = tmp;
+               }
                setenv("LD_PRELOAD", preload, 1);
+       }
 
        free(preload);