Skip to contentSkip to conversation

Make user-mode emu drop LD_PRELOAD

PATCH In review Lauri Leukkunen 2 participants 3 messages Apr 22, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make user-mode emu drop LD_PRELOAD

This patch makes user-mode emulation drop LD_PRELOAD environment variable by default and adds an option "-keep-ld-preload" to override this behaviour.

/lauri

Index: linux-user/main.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/main.c,v
retrieving revision 1.108

main.c +12 -6
diff -u -r1.108 main.c
@@ -1642,11 +1642,12 @@
            "usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
            "Linux CPU emulator (compiled for %s emulation)\n"
            "\n"
-           "-h           print this help\n"
-           "-g port      wait gdb connection to port\n"
-           "-L path      set the elf interpreter prefix (default=%s)\n"
-           "-s size      set the stack size in bytes (default=%ld)\n"
-           "-cpu model   select CPU (-cpu ? for list)\n"
+           "-h                print this help\n"
+           "-g port           wait gdb connection to port\n"
+           "-L path           set the elf interpreter prefix (default=%s)\n"
+           "-s size           set the stack size in bytes (default=%ld)\n"
+           "-cpu model        select CPU (-cpu ? for list)\n"
+           "-keep-ld-preload  retain LD_PRELOAD\n"
            "\n"
            "debug options:\n"
 #ifdef USE_CODE_COPY
@@ -1678,7 +1679,8 @@
     int optind;
     const char *r;
     int gdbstub_port = 0;
-    
+    int keep_ld_preload = 0;
+
     if (argc <= 1)
         usage();
 
@@ -1750,6 +1752,8 @@
 #endif
                 _exit(1);
             }
+        } else if (!strcmp(r, "keep-ld-preload")) {
+            keep_ld_preload = 1;
         } else 
 #ifdef USE_CODE_COPY
         if (!strcmp(r, "no-code-copy")) {
@@ -1778,6 +1782,8 @@
     env = cpu_init();
     global_env = env;
     
+    if (!keep_ld_preload) unsetenv("LD_PRELOAD");
+
     if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {
 	printf("Error loading %s\n", filename);
 	_exit(1);
#1 lore raw
Quoted 3 lines · Lauri Leukkunen

This patch makes user-mode emulation drop LD_PRELOAD environment variable by default and adds an option "-keep-ld-preload" to override this behaviour.

Why?

Paul

#2 lore raw
Quoted 6 lines · Paul Brook
Quoted 3 lines · Lauri Leukkunen

This patch makes user-mode emulation drop LD_PRELOAD environment variable by default and adds an option "-keep-ld-preload" to override this behaviour.

Why?

My use case is for scratchbox 2, I want to have libsb2.so preloaded for qemu-arm itself, but I don't want the target process to have to load it as there is no such library for it.

I just realized that this patch is probably not doing the right thing anyway, I think it should modify the target process environment in loader_exec instead of unsetting it for qemu itself, end result is more or less the same for simple cases, but I need to check where the environment is inherited from if the emulated process execs another.

/lauri