From: j.schauer@email.de
To: Riku Voipio <riku.voipio@iki.fi>,
Vagrant Cascadian <vagrant@freegeek.org>,
632192@bugs.debian.org, qemu-devel@nongnu.org
Cc: Johannes Schauer <j.schauer@email.de>
Subject: [Qemu-devel] [PATCH] introduce environment variables for all qemu-user options
Date: Sun, 31 Jul 2011 13:51:30 +0200 [thread overview]
Message-ID: <1312113090-23571-1-git-send-email-j.schauer@email.de> (raw)
In-Reply-To: <20110730135843.GA2492@afflict.kos.to>
From: Johannes Schauer <j.schauer@email.de>
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 <j.schauer@email.de>
---
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)
--
1.7.5.4
next prev parent reply other threads:[~2011-07-31 11:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-23 5:47 [Qemu-devel] [PATCH] add QEMU_LD_PREFIX environment variable josch
2011-07-23 5:47 ` josch
2011-07-28 8:41 ` Riku Voipio
2011-07-28 11:24 ` Johannes Schauer
2011-07-28 16:50 ` Geert Stappers
2011-07-28 17:28 ` Alexander Graf
2011-07-29 12:52 ` [Qemu-devel] Bug#632192: " Vagrant Cascadian
2011-07-29 15:21 ` Johannes Schauer
2011-07-30 13:58 ` Riku Voipio
2011-07-31 11:51 ` j.schauer [this message]
2011-07-31 12:12 ` [Qemu-devel] [PATCH] introduce environment variables for all qemu-user options Peter Maydell
2011-07-31 21:40 ` Johannes Schauer
2011-08-05 10:04 ` Peter Maydell
2011-08-06 6:54 ` Johannes Schauer
2011-08-20 17:29 ` Yann Dirson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1312113090-23571-1-git-send-email-j.schauer@email.de \
--to=j.schauer@email.de \
--cc=632192@bugs.debian.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=vagrant@freegeek.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.