From patchwork Sun Jul 31 11:51:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schauer X-Patchwork-Id: 107599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 10B53B6F81 for ; Sun, 31 Jul 2011 21:52:45 +1000 (EST) Received: from localhost ([::1]:59723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnUZU-00070I-QZ for incoming@patchwork.ozlabs.org; Sun, 31 Jul 2011 07:52:40 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnUZN-0006zv-GD for qemu-devel@nongnu.org; Sun, 31 Jul 2011 07:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QnUZM-0000xG-7z for qemu-devel@nongnu.org; Sun, 31 Jul 2011 07:52:33 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:52383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnUZL-0000wq-Nf for qemu-devel@nongnu.org; Sun, 31 Jul 2011 07:52:32 -0400 Received: from smtp06.web.de ( [172.20.5.172]) by fmmailgate02.web.de (Postfix) with ESMTP id 8000F1A7584AC; Sun, 31 Jul 2011 13:52:29 +0200 (CEST) Received: from [91.32.92.163] (helo=localhost.localdomain) by smtp06.web.de with asmtp (WEB.DE 4.110 #2) id 1QnUZJ-0003s4-00; Sun, 31 Jul 2011 13:52:29 +0200 From: j.schauer@email.de To: Riku Voipio , Vagrant Cascadian , 632192@bugs.debian.org, qemu-devel@nongnu.org Date: Sun, 31 Jul 2011 13:51:30 +0200 Message-Id: <1312113090-23571-1-git-send-email-j.schauer@email.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <20110730135843.GA2492@afflict.kos.to> References: <20110730135843.GA2492@afflict.kos.to> X-Sender: j.schauer@web.de X-Provags-ID: V01U2FsdGVkX19PruI1kCLSvfHdsYPEVjar+jUtC7WSrIwkUeoI l0MH2d+6meThsBSTJsK3aiK+/IT1XvG2EhK/9OR8CM7trPffnj n5SHuiyew= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.227 Cc: Johannes Schauer Subject: [Qemu-devel] [PATCH] introduce environment variables for all qemu-user options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Johannes Schauer A first try to introduce a generic setup for mapping environment variables to command line options. I'm afraid to code something for platforms I can't do runtime tests on, so this is only for linux-user for now. Signed-off-by: Johannes Schauer --- linux-user/main.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 144 insertions(+), 3 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index dbba8be..fb986e3 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -2640,26 +2640,51 @@ static void usage(void) "-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" + "-r uname set qemu uname release string\n" #if defined(CONFIG_USE_GUEST_BASE) "-B address set guest_base address to address\n" "-R size reserve size bytes for guest virtual address space\n" #endif "\n" + "Standard environment variables:\n" + "QEMU_GDB see the -g option\n" + "QEMU_LD_PREFIX see the -L option\n" + "QEMU_STACK_SIZE see the -s option\n" + "QEMU_CPU see the -cpu option\n" + "QEMU_SET_ENV see the -E option, comma separated list of arguments\n" + "QEMU_UNSET_ENV see the -U option, comma separated list of arguments\n" + "QEMU_ARGV0 see the -0 option\n" + "QEMU_UNAME see the -r option\n" +#if defined(CONFIG_USE_GUEST_BASE) + "QEMU_GUEST_BASE see the -B option\n" + "QEMU_RESERVED_VA see the -R option\n" +#endif + "\n" "Debug options:\n" "-d options activate log (logfile=%s)\n" "-p pagesize set the host page size to 'pagesize'\n" "-singlestep always run in singlestep mode\n" "-strace log system calls\n" "\n" - "Environment variables:\n" - "QEMU_STRACE Print system calls and arguments similar to the\n" - " 'strace' program. Enable by setting to any value.\n" + "Debug environment variables:\n" + "QEMU_LOG see the -d option\n" + "QEMU_PAGESIZE see the -p option\n" + "QEMU_SINGLESTEP see the -singlestep option\n" + "QEMU_STRACE see the -strace option\n" + "\n" "You can use -E and -U options to set/unset environment variables\n" "for target process. It is possible to provide several variables\n" "by repeating the option. For example:\n" " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n" "Note that if you provide several changes to single variable\n" "last change will stay in effect.\n" + "Using the environment variables QEMU_SET_ENV and QEMU_UNSET_ENV\n" + "to set/unset environment variables for target process is\n" + "possible by a comma separated list of values in getsubopt(3)\n" + "style. For example:\n" + " QEMU_SET_ENV=var1=val2,var2=val2 QEMU_UNSET_ENV=LD_PRELOAD,LD_DEBUG\n" + "Note that if you provide several changes to single variable\n" + "last change will stay in effect.\n" , TARGET_ARCH, interp_prefix, @@ -2758,6 +2783,122 @@ int main(int argc, char **argv, char **envp) cpudef_setup(); /* parse cpu definitions in target config file (TBD) */ #endif + if ((r = getenv("QEMU_LOG")) != NULL) { + int mask; + const CPULogItem *item; + mask = cpu_str_to_log_mask(r); + if (!mask) { + printf("Log items (comma separated):\n"); + for(item = cpu_log_items; item->mask != 0; item++) { + printf("%-10s %s\n", item->name, item->help); + } + exit(1); + } + cpu_set_log(mask); + } + if ((r = getenv("QEMU_SET_ENV")) != NULL) { + char *p, *token; + p = strdup(r); + while ((token = strsep(&p, ",")) != NULL) { + if (envlist_setenv(envlist, token) != 0) + usage(); + } + free(p); + } + if ((r = getenv("QEMU_UNSET_ENV")) != NULL) { + char *p, *token; + p = strdup(r); + while ((token = strsep(&p, ",")) != NULL) { + if (envlist_unsetenv(envlist, token) != 0) + usage(); + } + free(p); + } + if ((r = getenv("QEMU_ARGV0")) != NULL) { + argv0 = strdup(r); + } + if ((r = getenv("QEMU_STACK_SIZE")) != NULL) { + guest_stack_size = strtoul(r, (char **)&r, 0); + if (guest_stack_size == 0) + usage(); + if (*r == 'M') + guest_stack_size *= 1024 * 1024; + else if (*r == 'k' || *r == 'K') + guest_stack_size *= 1024; + } + if ((r = getenv("QEMU_LD_PREFIX")) != NULL) { + interp_prefix = strdup(r); + } + if ((r = getenv("QEMU_PAGESIZE")) != NULL) { + qemu_host_page_size = atoi(r); + if (qemu_host_page_size == 0 || + (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { + fprintf(stderr, "page size must be a power of two\n"); + exit(1); + } + } + if ((r = getenv("QEMU_GDB")) != NULL) { + gdbstub_port = atoi(r); + } + if ((r = getenv("QEMU_UNAME")) != NULL) { + qemu_uname_release = strdup(r); + } + if ((r = getenv("QEMU_CPU")) != NULL) { + cpu_model = strdup(r); + if (cpu_model == NULL || strcmp(cpu_model, "?") == 0) { +/* XXX: implement xxx_cpu_list for targets that still miss it */ +#if defined(cpu_list_id) + cpu_list_id(stdout, &fprintf, ""); +#elif defined(cpu_list) + cpu_list(stdout, &fprintf); /* deprecated */ +#endif + exit(1); + } + } +#if defined(CONFIG_USE_GUEST_BASE) + if ((r = getenv("QEMU_GUEST_BASE")) != NULL) { + guest_base = strtol(r, NULL, 0); + have_guest_base = 1; + } + if ((r = getenv("QEMU_QEMU_RESERVED_VA")) != NULL) { + char *p; + int shift = 0; + reserved_va = strtoul(r, &p, 0); + switch (*p) { + case 'k': + case 'K': + shift = 10; + break; + case 'M': + shift = 20; + break; + case 'G': + shift = 30; + break; + } + if (shift) { + unsigned long unshifted = reserved_va; + p++; + reserved_va <<= shift; + if (((reserved_va >> shift) != unshifted) +#if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS + || (reserved_va > (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) +#endif + ) { + fprintf(stderr, "Reserved virtual address too big\n"); + exit(1); + } + } + if (*p) { + fprintf(stderr, "Unrecognised -R size suffix '%s'\n", p); + exit(1); + } + } +#endif + if ((r = getenv("QEMU_SINGLESTEP")) != NULL) { + singlestep = 1; + } + optind = 1; for(;;) { if (optind >= argc)