From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lu7iN-00019y-Pu for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:11:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lu7iN-000197-3g for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:11:55 -0400 Received: from [199.232.76.173] (port=48810 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lu7iM-00018r-UA for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:11:54 -0400 Received: from savannah.gnu.org ([199.232.41.3]:50084 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lu7iL-0003NN-DG for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:11:54 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lu7iK-00077j-Q7 for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:11:52 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lu7iK-00077f-JU for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:11:52 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Wed, 15 Apr 2009 16:11:52 +0000 Subject: [Qemu-devel] [7115] linux-user: add support for passing contents of argv0 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7115 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7115 Author: aurel32 Date: 2009-04-15 16:11:52 +0000 (Wed, 15 Apr 2009) Log Message: ----------- 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 Signed-off-by: Aurelien Jarno Modified Paths: -------------- trunk/linux-user/main.c Modified: trunk/linux-user/main.c =================================================================== --- trunk/linux-user/main.c 2009-04-15 16:11:43 UTC (rev 7114) +++ trunk/linux-user/main.c 2009-04-15 16:11:52 UTC (rev 7115) @@ -2215,6 +2215,7 @@ "-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 @@ 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 @@ 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 @@ 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); }