delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/04/30/01:18:30

X-Spam-Check-By: sourceware.org
Message-ID: <44544896.10E80D75@dessent.net>
Date: Sat, 29 Apr 2006 22:18:14 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Truncated Environment Variables? - using Cygwin + GetEnvironmentStrings() WIN32 API
References: <44542B34 DOT 9000907 AT arkasoft DOT com> <44543FE2 DOT 5070208 AT arkasoft DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

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/

- Raw text -


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