delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/05/11/18:42:06

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
Message-ID: <42828A27.5050206@mscha.org>
Date: Thu, 12 May 2005 00:41:43 +0200
From: Michael Schaap <cygwin AT mscha DOT org>
Reply-To: cygwin AT cygwin DOT com
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Fixing strace and cygcheck so that they work with mount -X
References: <Pine DOT GSO DOT 4 DOT 61 DOT 0505081605450 DOT 21700 AT slinky DOT cs DOT nyu DOT edu> <20050508230637 DOT GD3896 AT trixie DOT casa DOT cgf DOT cx> <Pine DOT GSO DOT 4 DOT 61 DOT 0505081958360 DOT 21700 AT slinky DOT cs DOT nyu DOT edu> <20050509002126 DOT GH3896 AT trixie DOT casa DOT cgf DOT cx> <20050509022611 DOT GA7850 AT trixie DOT casa DOT cgf DOT cx> <427F9C41 DOT 1000605 AT acm DOT org> <427FB7B2 DOT 8040903 AT mscha DOT nl> <20050510151746 DOT GV15665 AT trixie DOT casa DOT cgf DOT cx> <42822503 DOT 2090903 AT mscha DOT org> <20050511154036 DOT GD10119 AT trixie DOT casa DOT cgf DOT cx> <20050511165354 DOT GA15412 AT trixie DOT casa DOT cgf DOT cx> <428255DA DOT 4030907 AT acm DOT org>
In-Reply-To: <428255DA.4030907@acm.org>
X-IsSubscribed: yes

--------------030504060307020405070400
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On 11-May-2005 20:58, David Rothenberger wrote:

> On 5/11/2005 9:53 AM, Christopher Faylor wrote:
>
>> On Wed, May 11, 2005 at 11:40:36AM -0400, Christopher Faylor wrote:
>>
>>> It sounds like you need to read MSDN on CreateProcess and see what
>>> it says
>>> about "lpEnvironment":
>>>
>>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
>>>
>>
>
> cygstart uses ShellExecute, not CreateProcess.
>
>> Btw, from the description, it sounds like cygstart is broken right now
>> and could be fixed right now.  You don't need any of the functionality
>> from the snapshot.  You just need to construct a windows lpEnvironment
>> block from the UNIX-like global variable, provided by cygwin: "extern
>> char **environ".
>
>
> The attached patch fixes cygstart for me. It copies all missing Cygwin
> environment variables to the Windows environment before invoking
> ShellExecute.
>
Indeed, that's the help I needed!  :-)

The patch as-is doesn't compile for me, though, I presume because
    char **envp = (char **) cygwin_internal (CW_ENVP);
uses a not-yet-released Cygwin enhancement.  But when I change it to the
simpler and more standard
    char **envp = environ;
it compiles and works fine, both under mount -X and normally.

(At first I was a bit suspicious of the logic - it only sets those
Windows variables that are not currently set, so what about variables
that were changed or deleted within Cygwin? - but it looks like the
Windows environment isn't the standard pre-Cygwin user environment, but
a minimal one with only PATH and SYSTEMROOT set, so it actually does
behave optimally this way - it sets all other variables when running
under mount -X, and sets nothing otherwise.)

Revised patch attached.  Can you try this out and see if it still works
for you?  If you confirm this, I'll resend the patch in a new, more
obviously titled thread, to attract Chuck's attention.  ;-)

Thanks for your and Chris' assistance,

 - Michael

--------------030504060307020405070400
Content-Type: text/plain;
 name="cygstart_winenv.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="cygstart_winenv.patch"

--- ORIG/cygstart.c	2005-03-08 06:22:51.000000000 +0100
+++ cygstart.c	2005-05-12 00:37:06.047250000 +0200
@@ -40,7 +40,7 @@
 #define MSDN_URL "http://msdn.microsoft.com/library/en-us/shellcc/platform/" \
                  "Shell/reference/functions/shellexecute.asp"
 
-static const char versionID[] = "1.0";
+static const char versionID[] = "1.2";
 /* for future CVS */
 static const char revID[] =
 	"$Id: cygstart.c,v 1.3 2005/03/08 05:22:51 cwilson Exp $";
@@ -64,6 +64,7 @@
 static void help(poptContext optCon, FILE *f, char *name);
 static void version(poptContext optCon, FILE *f, char *name);
 static void license(poptContext optCon, FILE *f, char *name);
+static void setup_win_environ(void);
 
 int main(int argc, const char **argv)
 {
@@ -404,6 +405,9 @@
 {
     int ret;
 
+    /* Need to sync the Windows environment when running under "mount -X" */
+    setup_win_environ();
+
     ret = (int) ShellExecute(NULL, action, aPath, args, workDir, show);
     if (ret >= 32) {
         return TRUE;
@@ -511,3 +515,25 @@
   printTopDescription(f, name);
   printLicense(f, name);
 }  
+
+/* Copy cygwin environment variables to the Windows environment if they're not
+ * already there. */
+static void setup_win_environ(void)
+{
+    char **envp = environ;
+    char *var, *val;
+    char curval[2];
+
+    while (envp && *envp) {
+        var = strdup(*envp++);
+        val = strchr(var, '=');
+        *val++ = '\0';
+        
+        if (GetEnvironmentVariable(var, curval, 2) == 0
+                    && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+            SetEnvironmentVariable(var, val);
+        }
+
+        free(var);
+    }
+}


--------------030504060307020405070400
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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