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


Kaveh Goudarzi wrote:

> 1. is it possible to somehow force cygwin to always sync
> the env with windows prior to spawning a child process (any
> child process)?

Well, you could always patch the DLL to not perform this optimization. 
I'm not sure if it's possible to do this in any other way.

> 2. How does cygwin work out if it's spawning a cygwin or
> non-cygwin binary?  (is it based on refs to cygwin1.dll?)
> (is it the loader that does this?)

I think it looks at the PE headers of the file for a record referring to
cygwin1.dll in the import section.  Or, if the path is mounted cygexec
this check is skipped and all binaries are assumed to be Cygwin
binaries, so you might be able to invert the sense of this somehow.

Also, there was some recent discussion about whether this optimization
was worth the headaches (in the context of programs that included
WinMain() failing when calling GetEnvironmentString()) and I think the
result was that the optimization was dropped... so I don't know what the
current state of this in CVS is.  I think cgf or Corinna (if she wasn't
away on vacation right now) would have to clarify here.

> 3. Brian mentioned a call to cygwin_internal(CW_SYNC_WINENV)
> In my scenario (see below) I'd have to work out if the target
> process was a cygwin proc or not before I tried to invoke this
> method ... is there a painless way of working out if a process
> is cygwin or not e.g. one that would give me a response whether
> the process I'm querying is a cygwin or a native win app?

#include <stdio.h>
#include <windows.h>

int main()
{
  HMODULE hm = GetModuleHandle ("cygwin1.dll");
  
  if (hm && GetProcAddress (hm, "cygwin_internal"))
    puts ("I appear to be a cygwin binary.");
  else
    puts ("Nope, no Cygwin here.");
}

Brian

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