delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/06/18/05:30:49

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 18 Jun 2008 05:30:16 -0400
From: Mike Mueller <mike AT subfocal DOT net>
To: cygwin AT cygwin DOT com
Subject: Re: Cygwin app not receiving modified PATH env var
Message-ID: <20080618093016.GG7632@samus.subfocal.net>
References: <20080617034152 DOT GD7632 AT samus DOT subfocal DOT net> <20080618010536 DOT GE7632 AT samus DOT subfocal DOT net> <20080618080059 DOT GF7632 AT samus DOT subfocal DOT net> <20080618085118 DOT GB20180 AT calimero DOT vinschen DOT de>
MIME-Version: 1.0
In-Reply-To: <20080618085118.GB20180@calimero.vinschen.de>
User-Agent: Mutt/1.5.17+20080114 (2008-01-14)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Thanks for the replies, Corinna.

> > A little further info.  It looks like apr detects a unicode environment,
> > so ultimately is calling CreateProcessW (not CreateProcessA).
> 
> How do you pass your unicode env?  Do you set the CREATE_UNICODE_ENVIRONMENT
> flag?

I get a snapshot of the current environment (GetEnvironmentStrings).
Then I create a new environment based on the current one, but adding
two additional variables and replacing PATH with a modified version of
the original PATH.

Then I hand it over to apr_proc_create, which ultimately calls
CreateProcessW.  If you're feeling bold, the implementation is here:
http://svn.apache.org/repos/asf/apr/apr/trunk/threadproc/win32/proc.c

I stepped through my program in the debugger, and yes, the
CREATE_UNICODE_ENVIRONMENT flag is set when apr_proc_create calls
CreateProcessW.  Also, I stepped through the apr code that constructs
the environment map that is passed to CreateProcessW, and my PATH
setting looks correct at that time.

> > Also, if I pass environment variables other than PATH, they are set
> > properly when the child executes.  I'm even able to override other
> > variables that are set already in the environment, and the new value is
> > seen by the child.  PATH is the only variable I can't get to work.
> 
> Is your environment big (> 32K)?  Up to 1.5.25 the environment is
> fetched using GetEnvironmentStringsA, which has a bug in (at least)
> Windows XP which results in a truncated environment in the child.  And
> it's not truncated to 32K, but much less from my testing.  Something
> along the lines of sizeof (child_env) == sizeof (parent_env) % 32K.

Nope, I just tallied up the size: 1486 bytes total.

> Other than that, I have no idea.  PATH is taken from the parent like
> any other env var.  Are you *sure* there's not some bug in your app?

Well, you never know, but I definitely try to see if it's my fault
before wasting anyone else's time.  To me, the key seems to be that
running a native windows app as the child works fine -- it receives the
PATH without any problem.  It's only running a cygwin child process where
the PATH is unchanged (even though 2 additional env vars other than PATH
get set properly).  This is the reason I'm asking on the cygwin list, and
not the apr list.

Obviously PATH is special to cygwin, because it has to transform the
Windows representation into a Unix-like representation.  I agree with
you that it *should* be pulled in like any other variable, but I'm not
familiar with cygwin's under-the-hood workings.  This problem has me
completely at a loss...

Thanks again,
Mike

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019