* [Qemu-devel] [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD
@ 2007-05-21 23:33 Lauri Leukkunen
2007-05-21 23:34 ` [Qemu-devel] " Lauri Leukkunen
0 siblings, 1 reply; 3+ messages in thread
From: Lauri Leukkunen @ 2007-05-21 23:33 UTC (permalink / raw)
To: qemu-devel
This patch adds an option "-drop-ld-preload" which results in the
target process not having LD_PRELOAD set in its environment. This is
useful when running inside environments like scratchbox.
This version of the patch doesn't unset("LD_PRELOAD") but modifies the
envp argument to loader_exec() instead.
/lauri
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] Re: [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD
2007-05-21 23:33 [Qemu-devel] [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD Lauri Leukkunen
@ 2007-05-21 23:34 ` Lauri Leukkunen
2007-05-22 0:00 ` Lauri Leukkunen
0 siblings, 1 reply; 3+ messages in thread
From: Lauri Leukkunen @ 2007-05-21 23:34 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 418 bytes --]
And here is the actual patch itself.
On 5/22/07, Lauri Leukkunen <lle@rahina.org> wrote:
> This patch adds an option "-drop-ld-preload" which results in the
> target process not having LD_PRELOAD set in its environment. This is
> useful when running inside environments like scratchbox.
>
> This version of the patch doesn't unset("LD_PRELOAD") but modifies the
> envp argument to loader_exec() instead.
>
> /lauri
>
[-- Attachment #2: qemu-linux-user-drop-preload2.diff --]
[-- Type: text/x-diff, Size: 2594 bytes --]
Index: linux-user/main.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/main.c,v
retrieving revision 1.109
diff -u -r1.109 main.c
--- linux-user/main.c 13 May 2007 13:58:00 -0000 1.109
+++ linux-user/main.c 21 May 2007 22:33:55 -0000
@@ -1666,11 +1666,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"
+ "-drop-ld-preload drop LD_PRELOAD for target process\n"
"\n"
"debug options:\n"
#ifdef USE_CODE_COPY
@@ -1702,7 +1703,9 @@
int optind;
const char *r;
int gdbstub_port = 0;
-
+ int drop_ld_preload = 0, environ_count = 0;
+ char **target_environ, **wrk, **dst;
+
if (argc <= 1)
usage();
@@ -1774,6 +1777,8 @@
#endif
_exit(1);
}
+ } else if (!strcmp(r, "drop-ld-preload")) {
+ drop_ld_preload = 1;
} else
#ifdef USE_CODE_COPY
if (!strcmp(r, "no-code-copy")) {
@@ -1802,11 +1807,25 @@
env = cpu_init();
global_env = env;
- if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {
- printf("Error loading %s\n", filename);
- _exit(1);
+ wrk = environ;
+ while (*(wrk++))
+ environ_count++;
+
+ target_environ = malloc((environ_count + 1) * sizeof(char *));
+ for (wrk = environ, dst = target_environ; *wrk; wrk++) {
+ if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
+ continue;
+ *(dst++) = strdup(*wrk);
}
-
+ dst = NULL; /* NULL terminate target_environ */
+
+ if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+ printf("Error loading %s\n", filename);
+ _exit(1);
+ }
+
+ free(target_environ);
+
if (loglevel) {
page_dump(logfile);
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] Re: [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD
2007-05-21 23:34 ` [Qemu-devel] " Lauri Leukkunen
@ 2007-05-22 0:00 ` Lauri Leukkunen
0 siblings, 0 replies; 3+ messages in thread
From: Lauri Leukkunen @ 2007-05-22 0:00 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
And while I'm at it here's the same with properly deallocated environ strings.
On 5/22/07, Lauri Leukkunen <lle@rahina.org> wrote:
> And here is the actual patch itself.
>
> On 5/22/07, Lauri Leukkunen <lle@rahina.org> wrote:
> > This patch adds an option "-drop-ld-preload" which results in the
> > target process not having LD_PRELOAD set in its environment. This is
> > useful when running inside environments like scratchbox.
> >
> > This version of the patch doesn't unset("LD_PRELOAD") but modifies the
> > envp argument to loader_exec() instead.
> >
> > /lauri
> >
>
>
[-- Attachment #2: qemu-linux-user-drop-preload3.diff --]
[-- Type: text/x-diff, Size: 2669 bytes --]
Index: linux-user/main.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/main.c,v
retrieving revision 1.109
diff -u -r1.109 main.c
--- linux-user/main.c 13 May 2007 13:58:00 -0000 1.109
+++ linux-user/main.c 21 May 2007 23:49:05 -0000
@@ -1666,11 +1666,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"
+ "-drop-ld-preload drop LD_PRELOAD for target process\n"
"\n"
"debug options:\n"
#ifdef USE_CODE_COPY
@@ -1702,7 +1703,9 @@
int optind;
const char *r;
int gdbstub_port = 0;
-
+ int drop_ld_preload = 0, environ_count = 0;
+ char **target_environ, **wrk, **dst;
+
if (argc <= 1)
usage();
@@ -1774,6 +1777,8 @@
#endif
_exit(1);
}
+ } else if (!strcmp(r, "drop-ld-preload")) {
+ drop_ld_preload = 1;
} else
#ifdef USE_CODE_COPY
if (!strcmp(r, "no-code-copy")) {
@@ -1802,11 +1807,29 @@
env = cpu_init();
global_env = env;
- if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {
- printf("Error loading %s\n", filename);
- _exit(1);
+ wrk = environ;
+ while (*(wrk++))
+ environ_count++;
+
+ target_environ = malloc((environ_count + 1) * sizeof(char *));
+ for (wrk = environ, dst = target_environ; *wrk; wrk++) {
+ if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
+ continue;
+ *(dst++) = strdup(*wrk);
+ }
+ dst = NULL; /* NULL terminate target_environ */
+
+ if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+ printf("Error loading %s\n", filename);
+ _exit(1);
+ }
+
+ for (wrk = target_environ; *wrk; wrk++) {
+ free(*wrk);
}
+ free(target_environ);
+
if (loglevel) {
page_dump(logfile);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-05-22 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-21 23:33 [Qemu-devel] [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD Lauri Leukkunen
2007-05-21 23:34 ` [Qemu-devel] " Lauri Leukkunen
2007-05-22 0:00 ` Lauri Leukkunen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).