This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Truncated Environment Variables? - using Cygwin + GetEnvironmentStrings() WIN32 API


> 
> 	I'm working on an app which attempts to get
> the environment of running cygwin apps.  It does this
> by running the GetEnvironmentStrings() win32 api call
> in the context of the running cygwin app (code injection).

That is somewhat risky, as recent threads have discussed how
windows update does a code injection that interferes with cygwin
and deadlocks the processor into 100% utilization.

> However the result that comes back as a truncated version of
> the environment - only 4 values PATH, SYSTEMDRIVE, SYSTEMROOT,
> WINDIR.

Correct.  That's all the more cygwin processes use of the Windows
environment.  Going through Windows is slow and limited, so
cygwin uses its own environment, converting to Windows only
at the last minute when spawning a non-cygwin process.

> 
> 	I saw the article below which seems relevant but I
> was confused because my understanding of it would mean that
> the call using win32 api should fail when run under both cmd.exe
> and bash.exe which is not the case.
> 
> http://cygwin.com/ml/cygwin/2006-01/msg00938.html

A cygwin process invoked directly from cmd.com (currently)
does not go out of its way to clear the environment, but
child processes of cygwin do not waste time propagating
everything via the Windows environment.

> 
> 	I would be most grateful if someone could tell me
> why this might be happening and what possible alternative
> paths I could follow.

If you wanted to be more like Linux, you could implement
something in the /proc virtual file system that enumerated
the environment of a particular process; by asking cygwin
what cygwin thinks the environment, and without thread
injection, you would get a better answer than by asking
Windows about the cygwin environment; plus, you will be
isolated from any further implementation changes cygwin
makes with its under-the-hood handling of the environ.

Why do you need to know the environment of a running
cygwin process, anyways?  Perhaps explaining your
need would allow us to come up with an alternative
approach.

> 
> PS. I've attached the output of "cygcheck -s -v -r > cygcheck.out"

Actually, you attached a one line file with contents "cygcheck -s -v -r".

-- 
Eric Blake


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]