From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV2Ic-0007jB-L0 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 12:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UV2IW-0002J0-F7 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 12:12:02 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:65379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UV2IW-0002Io-5h for qemu-devel@nongnu.org; Wed, 24 Apr 2013 12:11:56 -0400 From: Thomas Schwinge In-Reply-To: <87txmwoyqc.fsf@schwinge.name> References: <87txmwoyqc.fsf@schwinge.name> Date: Wed, 24 Apr 2013 18:11:46 +0200 Message-ID: <87k3nrq56l.fsf@schwinge.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: Re: [Qemu-devel] Environment variables for user-mode QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: paul@codesourcery.com, Johannes Schauer --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! On Wed, 24 Apr 2013 15:16:27 +0200, I wrote: > We have a need to pass environment variable assignments containing commas > to user-mode QEMU. The usage information currently says: >=20 > You can use -E and -U options or the QEMU_SET_ENV and > QEMU_UNSET_ENV environment variables to set and unset > environment variables for the target process. > It is possible to provide several variables by separating them > by commas in getsubopt(3) style. Additionally it is possible to > provide the -E and -U options multiple times. >=20 > $ env -i x86_64-linux-user/qemu-x86_64 -E x=3Dy,y=3Dz /usr/bin/printe= nv > y=3Dz > x=3Dy >=20 > Instead of this, we'd like to see: >=20 > $ env -i x86_64-linux-user/qemu-x86_64 -E x=3Dy,y=3Dz /usr/bin/printe= nv > x=3Dy,y=3Dz >=20 > Due to the tokenization based on comma in > linux-user/main.c:handle_arg_set_env, there is currently no way to > achieve this -- other than pre-setting environment variables before > running user-mode QEMU, which obviously isn't always desirable/possible > (LD_LIBRARY_PATH, etc.). >=20 > Assuming there is a consensus, how would you like this implemented? >=20 > Is it OK to change the semantics of -E (as well as -U, for symmetry?) to > not handle multiple environment variable assignments (preliminary patch > below), or does that functionality need to be preserved? Something needs > to be done about QEMU_SET_ENV and QEMU_UNSET_ENV then (if anyone is using > these at all, which we can't disprove), as these are not very useful if > they can handle only one environment variable. That is actually a "regression"/change introduced in commit fc9c54124d134dbd76338a92a91804dab2df8166 (Johannes Schauer CCed, for your information). I'm attaching 0001-linux-user-Document-E-and-U-options.patch to update the documentation for the linux-user QEMU. The bsd-user QEMU has not been changed accordingly, by the way. I'm attaching 0002-linux-user-Use-existing-envlist_parse_set-envlist_pa.patch for some code simplifications. > Or, should we perhaps have a new -env option that causes any later > non-option arguments, that contain an equal sign, to be handled as > environment variable assignments, just like the env command does? >=20 > $ env -i x86_64-linux-user/qemu-x86_64 [some options] -env [more opti= ons] a=3Db,c d=3De,f=3Da /usr/bin/printenv > a=3Db,c > d=3De,f=3Da >=20 > I think I might prefer that solution. As it is a new option, it also > won't interfere with anyone's usage/expectations of the current behavior. I'm attaching 0003-linux-user-New-env-option.patch for implementing that. The patches have only been lightly tested; please review. Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-linux-user-Document-E-and-U-options.patch Content-Transfer-Encoding: quoted-printable From=20eaf53af8d75e001969a658d83d71dd48324c6bcb Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 24 Apr 2013 17:41:58 +0200 Subject: [PATCH 1/3] linux-user: Document -E and -U options. Document changed behavior introducecd in commit fc9c54124d134dbd76338a92a91804dab2df8166. Signed-off-by: Thomas Schwinge =2D-- qemu-doc.texi | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git qemu-doc.texi qemu-doc.texi index dfea4d3..3034af4 100644 =2D-- qemu-doc.texi +++ qemu-doc.texi @@ -2683,13 +2683,11 @@ Set the x86 elf interpreter prefix (default=3D/usr/= local/qemu-i386) Set the x86 stack size in bytes (default=3D524288) @item -cpu model Select CPU model (-cpu help for list and additional feature selection) =2D@item -ignore-environment =2DStart with an empty environment. Without this option, =2Dthe initial environment is a copy of the caller's environment. =2D@item -E @var{var}=3D@var{value} =2DSet environment @var{var} to @var{value}. =2D@item -U @var{var} =2DRemove @var{var} from the environment. +@item -E @var{var}=3D@var{value}[,@var{var2}=3D@var{value2},...] +Set environment @var{var} to @var{value}, @var{var2} to @var{value2}, +and so on. +@item -U @var{var}[,var2,...] +Remove @var{var}, @var{var2}, and so on from the environment. @item -B offset Offset guest address by the specified number of bytes. This is useful when the address region required by guest applications is reserved on the host. =2D-=20 1.7.10.4 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-linux-user-Use-existing-envlist_parse_set-envlist_pa.patch Content-Transfer-Encoding: quoted-printable From=20540f9fa2e9eb197bde3cb91403b6eaaa7d78ac4d Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 24 Apr 2013 17:28:02 +0200 Subject: [PATCH 2/3] linux-user: Use existing envlist_parse_set/envlist_parse_unset interface. Signed-off-by: Thomas Schwinge =2D-- linux-user/main.c | 18 ++++-------------- util/envlist.c | 4 ++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git linux-user/main.c linux-user/main.c index 4e92a0b..7f81821 100644 =2D-- linux-user/main.c +++ linux-user/main.c @@ -3204,26 +3204,16 @@ static void handle_arg_log_filename(const char *arg) =20 static void handle_arg_set_env(const char *arg) { =2D char *r, *p, *token; =2D r =3D p =3D strdup(arg); =2D while ((token =3D strsep(&p, ",")) !=3D NULL) { =2D if (envlist_setenv(envlist, token) !=3D 0) { =2D usage(); =2D } + if (envlist_parse_set(envlist, arg) !=3D 0) { + usage(); } =2D free(r); } =20 static void handle_arg_unset_env(const char *arg) { =2D char *r, *p, *token; =2D r =3D p =3D strdup(arg); =2D while ((token =3D strsep(&p, ",")) !=3D NULL) { =2D if (envlist_unsetenv(envlist, token) !=3D 0) { =2D usage(); =2D } + if (envlist_parse_unset(envlist, arg) !=3D 0) { + usage(); } =2D free(r); } =20 static void handle_arg_argv0(const char *arg) diff --git util/envlist.c util/envlist.c index ebc06cf..4dbca28 100644 =2D-- util/envlist.c +++ util/envlist.c @@ -55,10 +55,10 @@ envlist_free(envlist_t *envlist) =20 /* * Parses comma separated list of set/modify environment =2D * variable entries and updates given enlist accordingly. + * variable entries and updates given envlist accordingly. * * For example: =2D * envlist_parse(el, "HOME=3Dfoo,SHELL=3D/bin/sh"); + * envlist_parse_set(el, "HOME=3Dfoo,SHELL=3D/bin/sh"); * * inserts/sets environment variables HOME and SHELL. * =2D-=20 1.7.10.4 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-linux-user-New-env-option.patch Content-Transfer-Encoding: quoted-printable From=2071461a2caccfc31287e26ca1edf8ff0053a563f7 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 24 Apr 2013 17:59:17 +0200 Subject: [PATCH 3/3] linux-user: New -env option. Signed-off-by: Thomas Schwinge =2D-- linux-user/main.c | 29 ++++++++++++++++++++++++++++- qemu-doc.texi | 6 +++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git linux-user/main.c linux-user/main.c index 7f81821..7b38b54 100644 =2D-- linux-user/main.c +++ linux-user/main.c @@ -38,6 +38,7 @@ char *exec_path; =20 int singlestep; +int env_mode; const char *filename; const char *argv0; int gdbstub_port; @@ -3202,6 +3203,11 @@ static void handle_arg_log_filename(const char *arg) qemu_set_log_filename(arg); } =20 +static void handle_arg_env(const char *arg) +{ + env_mode =3D 1; +} + static void handle_arg_set_env(const char *arg) { if (envlist_parse_set(envlist, arg) !=3D 0) { @@ -3354,6 +3360,8 @@ static const struct qemu_argument arg_table[] =3D { "size", "set the stack size to 'size' bytes"}, {"cpu", "QEMU_CPU", true, handle_arg_cpu, "model", "select CPU (-cpu help for list)"}, + {"env", "", false, handle_arg_env, + "", "enable parsing of the ENV LIST (see below)"}, {"E", "QEMU_SET_ENV", true, handle_arg_set_env, "var=3Dvalue", "sets targets environment variable (see below)"}, {"U", "QEMU_UNSET_ENV", true, handle_arg_unset_env, @@ -3390,7 +3398,7 @@ static void usage(void) int maxarglen; int maxenvlen; =20 =2D printf("usage: qemu-" TARGET_ARCH " [options] program [arguments...]= \n" + printf("usage: qemu-" TARGET_ARCH " [options] [env list] program [argu= ments...]\n" "Linux CPU emulator (compiled for " TARGET_ARCH " emulation)\n" "\n" "Options and associated environment variables:\n" @@ -3444,9 +3452,11 @@ static void usage(void) "It is possible to provide several variables by separating them= \n" "by commas in getsubopt(3) style. Additionally it is possible t= o\n" "provide the -E and -U options multiple times.\n" + "Only with -env it is possible to specify values containing com= mas.\n" "The following lines are equivalent:\n" " -E var1=3Dval2 -E var2=3Dval2 -U LD_PRELOAD -U LD_DEBUG\n" " -E var1=3Dval2,var2=3Dval2 -U LD_PRELOAD,LD_DEBUG\n" + " -env -U LD_PRELOAD,LD_DEBUG var1=3Dval2 var2=3Dval2\n" " QEMU_SET_ENV=3Dvar1=3Dval2,var2=3Dval2 QEMU_UNSET_ENV=3DLD= _PRELOAD,LD_DEBUG\n" "Note that if you provide several changes to a single variable\= n" "the last change will stay in effect.\n"); @@ -3507,6 +3517,23 @@ static int parse_args(int argc, char **argv) } } =20 + if (env_mode) { + for (;;) { + if (optind >=3D argc) { + break; + } + r =3D argv[optind]; + if (strchr(r, '=3D') =3D=3D NULL) { + break; + } + if (envlist_setenv(envlist, r) !=3D 0) { + usage(); + } + + optind++; + } + } + if (optind >=3D argc) { usage(); } diff --git qemu-doc.texi qemu-doc.texi index 3034af4..f48a53e 100644 =2D-- qemu-doc.texi +++ qemu-doc.texi @@ -2671,7 +2671,7 @@ qemu-i386 /usr/local/qemu-i386/wine/bin/wine \ @subsection Command line options =20 @example =2Dusage: qemu-i386 [-h] [-d] [-L path] [-s size] [-cpu model] [-g port] [-= B offset] [-R size] program [arguments...] +usage: qemu-i386 [-h] [-d] [-L path] [-s size] [-cpu model] [-g port] [-B = offset] [-R size] [env list] program [arguments...] @end example =20 @table @option @@ -2683,6 +2683,10 @@ Set the x86 elf interpreter prefix (default=3D/usr/l= ocal/qemu-i386) Set the x86 stack size in bytes (default=3D524288) @item -cpu model Select CPU model (-cpu help for list and additional feature selection) +@item -env +Enable parsing of the @var{env list}. This means that any +@var{var}=3D@var{value} assignments before @var{program} will be added +to the environment. @item -E @var{var}=3D@var{value}[,@var{var2}=3D@var{value2},...] Set environment @var{var} to @var{value}, @var{var2} to @var{value2}, and so on. =2D-=20 1.7.10.4 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJReARCAAoJENuKOtuXzphJwBwH/2lBg39myNjWjNNw4x9nB+a8 +9CjDhDpYlcECivLQxGGaXU4wTi0161bfMlcQCnvvmChlIGTYjYrtQby46Y338fj eS5ut5vN7xBuXtPpPRAeX/0hCsiS/GDAtamevhJyhEUR6bKrgFztHb5hsWnKOBQc +gFeT+TocZjymrhox6HgoEi7ilczZYa5bK+FfFSPhkg1ZzsJBqtAJmHcblYEP2Sf 6evYIpJUkBc302F2b8FA8wAeAPk+T+reUGwDBZaddC2Vl7+ZAYPjl8CNmi4mQx9X 7CKr5ybhAPOBXSMm+naUE5xZuGmwVI7ji9TxQ7wtGWju584R3lTMP7Fo/Vsgqeg= =JypS -----END PGP SIGNATURE----- --==-=-=--