From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUzYz-0008MB-87 for qemu-devel@nongnu.org; Wed, 24 Apr 2013 09:16:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUzYu-0002Lj-9W for qemu-devel@nongnu.org; Wed, 24 Apr 2013 09:16:45 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:43103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUzYu-0002LD-3X for qemu-devel@nongnu.org; Wed, 24 Apr 2013 09:16:40 -0400 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1UUzYr-0003mg-Qu from Thomas_Schwinge@mentor.com for qemu-devel@nongnu.org; Wed, 24 Apr 2013 06:16:37 -0700 From: Thomas Schwinge Date: Wed, 24 Apr 2013 15:16:27 +0200 Message-ID: <87txmwoyqc.fsf@schwinge.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Subject: [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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! We have a need to pass environment variable assignments containing commas to user-mode QEMU. The usage information currently says: 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. $ env -i x86_64-linux-user/qemu-x86_64 -E x=3Dy,y=3Dz /usr/bin/printenv y=3Dz x=3Dy Instead of this, we'd like to see: $ env -i x86_64-linux-user/qemu-x86_64 -E x=3Dy,y=3Dz /usr/bin/printenv x=3Dy,y=3Dz 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.). Assuming there is a consensus, how would you like this implemented? 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. 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? $ env -i x86_64-linux-user/qemu-x86_64 [some options] -env [more option= s] a=3Db,c d=3De,f=3Da /usr/bin/printenv a=3Db,c d=3De,f=3Da 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. Anyway, here is the incomplete patch, changing the behavior of -E and -U (as well as the corresponding QEMU_SET_ENV and QEMU_UNSET_ENV): diff --git linux-user/main.c linux-user/main.c index 4e92a0b..62ff963 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_setenv(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_unsetenv(envlist, arg) !=3D 0) { + usage(); } =2D free(r); } =20 static void handle_arg_argv0(const char *arg) Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJRd9ssAAoJENuKOtuXzphJev8H/2PNsjcTuyGoVO2r7TNFfBlo fjAtkcYYcuoQoLIsxVBY3RBBSw76VqGs/THQATWaQNZQFSoJkxbIrYEFlSJi0Aga V+0z1A9PzlStTpFO6oMJkbxh9K9Y8N7GbdjypKonSC6KqEMkGgfKro6NKEJhuZTR U3kkZ9TORZ9S+dZrQNUel0Db39/565BmbLjE37Go+yObWur2tq9t7/Ga5HYXAtta EidXqgQlQDIwE34yb9jb1mvJXHNP7u7ZdRyFAYWuCYAnZ6If3Rqgf4UMWVvxW+yU sBycdeeByy7gNkTeA7mTeouzGYVKgp4HsJAymnmm+DMRfyXnY2TfTNj+L5Q3TmU= =eoGo -----END PGP SIGNATURE----- --=-=-=--