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: strange cygstart bug with current Cygwin versions


On 6-Feb-2006 22:29, David Picton wrote:
> On 2/3/06, Igor Peshansky <pechtcha@cs.nyu.edu> wrote:
>   
>> Sounds like an instance of
>> <http://cygwin.com/ml/cygwin/2005-05/msg00587.html>...  Does it work if
>> you "cygstart cmd" and then start word from that cmd shell?  If you get
>> the same symptoms, please run "set" in that cmd window and compare the
>> output with the same in a cmd started via "Start->Run"...
>>     
>
> I get the same symptoms, and now I can see what the problem is.  The 
> CMD window shows that TEMP and TMP have retained Cygwin-style
> pathnames:
>
> TEMP=/cygdrive/c/DOCUME~1/dave/LOCALS~1/Temp
> TMP=/cygdrive/c/DOCUME~1/dave/LOCALS~1/Temp
>
> Word works OK if I set TMP to a proper Windows pathname e.g. D:\cygwin\tmp
>
>   
Hmm, indeed it does ...

Under Cygwin 1.5.18, a process started using the Win32 ShellExecute
function (which cygstart uses) inherits the entire Cygwin environment,
with the appropriate variables, including TEMP and TMP, converted from
POSIX to Windows standard.

Under Cygwin 1.5.19, however, it only appears to inherit the following
variables: COMSPEC, PATH, PATHEXT, PROMPT, SYSTEMDRIVE and SYSTEMROOT
and WINDIR.

Some code was added to cygstart last May that copies all enviroment
variables from the Cygwin enviroment to the Windows enviroment, if they
don't exist there yet.  This was apparently needed in some obscure
circumstances at the time (regarding "mount -X", I think), but it looks
like it is now always necessary.
(See <http://cygwin.com/ml/cygwin/2005-05/msg00587.html> and
<http://cygwin.com/ml/cygwin/2005-05/msg00404.html>, among others.)

This code has no special handling for path conversion.  We knew that
PATH was already in the Windows environment, so we didn't have to care
about that one.  But we didn't think of other variables...

I had a look at the Cygwin source code, and, in environment.cc, it seems
to do path conversion for the following variables: PATH, HOME,
LD_LIBRARY_PATH, TMPDIR, TMP and TEMP.  So, we should probably do so in
cygstart as well...
However, I'd rather not have to hardcode all of this in the cygstart
source code, since it is bound to get out of sync at some point.  So,
I'm hoping there is some way to use some Cygwin functionality directly.

Is there anyone with a better grasp of Cygwin's environment handling
code that could help with this, perhaps?
What we basically need to do, is copy the Cygwin environment to the
Windows environment, taking care of path conversion for all the
appropriate variables.

The current code we use is as follows:

/* 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);
    }
}

Thanks in advance,

 - Michael

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