From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27425 invoked by alias); 4 Oct 2011 16:11:51 -0000 Received: (qmail 27410 invoked by uid 22791); 4 Oct 2011 16:11:47 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT,TW_CP X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.151) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 04 Oct 2011 16:11:33 +0000 Received: from md1.u-strasbg.fr (md1.u-strasbg.fr [IPv6:2001:660:2402::186]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p94GBVjb013181 for ; Tue, 4 Oct 2011 18:11:31 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms2.u-strasbg.fr [130.79.204.11]) by md1.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p94GBV6P047802 for ; Tue, 4 Oct 2011 18:11:31 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p94GBVqi086989 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 4 Oct 2011 18:11:31 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: References: <006301cc8292$367539b0$a35fad10$@muller@ics-cnrs.unistra.fr> <20111004134506.GB24369@calimero.vinschen.de> <000901cc82a4$dfba7cd0$9f2f7670$@muller@ics-cnrs.unistra.fr> <20111004151236.GC15757@calimero.vinschen.de> In-Reply-To: <20111004151236.GC15757@calimero.vinschen.de> Subject: RE: [RFA] testsuite: Add a test for passing of environment variables to inferior Date: Tue, 04 Oct 2011 16:11:00 -0000 Message-ID: <003901cc82b0$471e3a00$d55aae00$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00094.txt.bz2 > -----Message d'origine----- > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Corinna Vinschen > Envoy=C3=A9 : mardi 4 octobre 2011 17:13 > =C3=80 : gdb-patches@sourceware.org > Objet : Re: [RFA] testsuite: Add a test for passing of environment variab= les > to inferior >=20 > On Oct 4 16:49, Pierre Muller wrote: > > > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > > > owner@sourceware.org] De la part de Corinna Vinschen > > > Yes, that would be necessary. I'm wondering if we can't just utilze = the > > > global environ variable for this and spare us all the hassle. Someth= ing > > > along these lines: > > > > > > char **old_env =3D environ; > > > environ =3D in_env; > > > cygwin_internal (CW_SYNC_WINENV); > > > CreateProcessW (NULL environment pointer); > > > environ =3D old_env; > > > > I checked it out, but it still > > fails for the last test, the missing TEST_GDB_VAR1 > > variable doesn't get removed from GDB environment list > > apparently (This is probably related to the internals > > of cygwin_internal (CW_SYNC_WINENV), no? >=20 > Right. The problem is that there's no simple Win32 call to set (or > clear) the Windows environment in one go. So CW_SYNC_WINENV only sets > but never unsets because that would require to check each Windows > variable if it exists in the POSIX env or not. That was more effort > than seemed to make sense at the time. >=20 > > Manually resetting all variables should help... >=20 > Yes, but that's far from elegant. I don't mean your patch, but the fact > that it seems to be necessary at all. Maybe we should introduce some > new cygwin_internal call, which produces a Win32 environment from a > POSIX environment without affecting the Win32 environment of the calling > process: >=20 > LPWCH out_env =3D (LPWCH) cygwin_internal (CW_CREATE_WIN32_ENV, in_env); > CreateProcess (..., CREATE_UNICODE_ENVIRONMENT, ..., out_env, ...); > free (new_env); >=20 > But that would only work for newer Cygwin releases, so that's just > a future option. >=20 > > The patch below does not generate any failure on my test, > > but I am still not sure what happens if you try to > > remove an environment variable that was set when GDB started... >=20 > GDB should not be affected. Its POSIX environment is still intact and > that's all what's used when interacting with the underlying Cygwin POSIX > calls. The only variable which should have an effect is $PATH, and that's > restored by the final cygwin_internal(CW_SYNC_WINENV) call. So, AFAICS, > your patch should be fine. Nor completely yet, here is an update that unsets all environment variables both in environ list before calling CreateProcess and in in_env list after... This passes the new updated test I just sent. 2011-10-04 Pierre Muller * windows-nat.c (windows_create_inferior): Handle in_env array for Cygwin GDB. * testsuite/gdb.base/setshow.exp (gdb_test): Add test to check that 'unset environment' works. Index: windows-nat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.219 diff -u -p -r1.219 windows-nat.c --- windows-nat.c 28 Sep 2011 09:07:54 -0000 1.219 +++ windows-nat.c 4 Oct 2011 16:05:36 -0000 @@ -1980,8 +1980,9 @@ windows_create_inferior (struct target_o cygwin_buf_t *toexec; cygwin_buf_t *cygallargs; cygwin_buf_t *args; + char **old_env; size_t len; - int tty; + int tty, i; int ostdin, ostdout, ostderr; #else char real_path[__PMAX]; @@ -2066,6 +2067,19 @@ windows_create_inferior (struct target_o strcat (args, cygallargs); #endif =20 + /* Reset all environment variables to avoid leftover on next run. */ + for (i =3D 0; environ[i] && *environ[i]; i++) + { + char *equalpos; + char *copy =3D alloca (strlen(environ[i]) + 1); + strcpy (copy, environ[i]); + equalpos =3D strchr (copy, '=3D'); + if (equalpos) + *equalpos =3D '\0'; + SetEnvironmentVariableA (copy, NULL); + } + old_env =3D environ; + environ =3D in_env; /* Prepare the environment vars for CreateProcess. */ cygwin_internal (CW_SYNC_WINENV); =20 @@ -2101,6 +2115,20 @@ windows_create_inferior (struct target_o NULL, /* current directory */ &si, &pi); + /* Reset all environment variables to avoid leftover on next run. */ + for (i =3D 0; in_env[i] && *in_env[i]; i++) + { + char *equalpos =3D strchr (in_env[i], '=3D'); + if (equalpos) + *equalpos =3D '\0'; + SetEnvironmentVariableA (in_env[i], NULL); + if (equalpos) + *equalpos =3D '=3D'; + } + /* Restore normal GDB environment variables. */ + environ =3D old_env; + cygwin_internal (CW_SYNC_WINENV); + if (tty >=3D 0) { close (tty);