diff options
author | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 16:11:52 +0000 |
---|---|---|
committer | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 16:11:52 +0000 |
commit | 7d8cec95c84bbfe86462aa048dc62c9e18263015 (patch) | |
tree | b8573355c331d6388fedb112b2b1bf55ed05b577 /linux-user/main.c | |
parent | 24e1003a524922782bb0290ecceef01676f92c16 (diff) |
linux-user: add support for passing contents of argv0
Added switch -0 (zero) which can be used to pass argv[0] to
target process. The main use is for a binfmt_misc wrapper when
the "P - preserve-argv[0]" setting is used.
From: Mika Westerberg
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7115 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'linux-user/main.c')
-rw-r--r-- | linux-user/main.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/linux-user/main.c b/linux-user/main.c index 21e8128b07..b6b02fd5a1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -2215,6 +2215,7 @@ static void usage(void) "-drop-ld-preload drop LD_PRELOAD for target process\n" "-E var=value sets/modifies targets environment variable(s)\n" "-U var unsets targets environment variable(s)\n" + "-0 argv0 forces target process argv[0] to be argv0\n" "\n" "Debug options:\n" "-d options activate log (logfile=%s)\n" @@ -2266,7 +2267,11 @@ int main(int argc, char **argv, char **envp) const char *r; int gdbstub_port = 0; char **target_environ, **wrk; + char **target_argv; + int target_argc; envlist_t *envlist = NULL; + const char *argv0 = NULL; + int i; if (argc <= 1) usage(); @@ -2323,6 +2328,9 @@ int main(int argc, char **argv, char **envp) r = argv[optind++]; if (envlist_unsetenv(envlist, r) != 0) usage(); + } else if (!strcmp(r, "0")) { + r = argv[optind++]; + argv0 = r; } else if (!strcmp(r, "s")) { if (optind >= argc) break; @@ -2435,11 +2443,39 @@ int main(int argc, char **argv, char **envp) target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); - if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) { + /* + * Prepare copy of argv vector for target. + */ + target_argc = argc - optind; + target_argv = calloc(target_argc + 1, sizeof (char *)); + if (target_argv == NULL) { + (void) fprintf(stderr, "Unable to allocate memory for target_argv\n"); + exit(1); + } + + /* + * If argv0 is specified (using '-0' switch) we replace + * argv[0] pointer with the given one. + */ + i = 0; + if (argv0 != NULL) { + target_argv[i++] = strdup(argv0); + } + for (; i < target_argc; i++) { + target_argv[i] = strdup(argv[optind + i]); + } + target_argv[target_argc] = NULL; + + if (loader_exec(filename, target_argv, target_environ, regs, info) != 0) { printf("Error loading %s\n", filename); _exit(1); } + for (i = 0; i < target_argc; i++) { + free(target_argv[i]); + } + free(target_argv); + for (wrk = target_environ; *wrk; wrk++) { free(*wrk); } |