diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 4e049211e9..87813e2207 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -180,7 +180,7 @@ strbrk(char *&buf) /* Parse a string of the form "something=stuff somethingelse=more-stuff", silently ignoring unknown "somethings". */ static void -parse_options (const char *inbuf) +parse_options (const char *inbuf, bool is_msys2) { int istrue; parse_thing *k; @@ -201,11 +201,10 @@ parse_options (const char *inbuf) if (export_settings) { debug_printf ("%s", newbuf + 1); -#ifdef __MSYS__ - setenv ("MSYS", newbuf + 1, 1); -#else - setenv ("CYGWIN", newbuf + 1, 1); -#endif + if (is_msys2) + setenv ("MSYS", newbuf + 1, 1); + else + setenv ("CYGWIN", newbuf + 1, 1); } return; } @@ -679,7 +678,9 @@ _addenv (const char *name, const char *value, int overwrite) if ((spenv = getwinenv (envhere))) spenv->add_cache (value); if (strcmp (name, "MSYS") == 0) - parse_options (value); + parse_options (value, true); + if (strcmp (name, "CYGWIN") == 0) + parse_options (value, false); return 0; } @@ -877,13 +878,12 @@ environ_init (char **envp, int envc) dumper_init (); if (envp_passed_in) { -#ifdef __MSYS__ p = getenv ("MSYS"); -#else + if (p) + parse_options (p, true); p = getenv ("CYGWIN"); -#endif if (p) - parse_options (p); + parse_options (p, false); } } __except (NO_ERROR) @@ -937,13 +937,10 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify) } sawTERM = 1; } -#ifdef __MSYS__ else if (*newp == 'M' && strncmp (newp, "MSYS=", 5) == 0) - parse_options (newp + 5); -#else + parse_options (newp + 5, true); else if (*newp == 'C' && strncmp (newp, "CYGWIN=", 7) == 0) - parse_options (newp + 7); -#endif + parse_options (newp + 7, false); if (*eq && posify) posify_maybe (envp + i, *++eq ? eq : --eq, tmpbuf); debug_printf ("%p: %s", envp[i], envp[i]); @@ -1206,8 +1203,12 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc, #ifdef __MSYS__ if (ascii_strncasematch(*srcp, "MSYS=", 5)) { - parse_options (*srcp + 5); - } + parse_options (*srcp + 5, true); + } + else if (ascii_strncasematch(*srcp, "CYGWIN=", 7)) + { + parse_options (*srcp + 7, false); + } else if (!keep_posix) { /* Don't pass timezone environment to non-msys applications */ diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index bdbf443c9b..1debcb28fe 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -529,6 +529,17 @@ int exec_prepared_command (PWCHAR command) PWCHAR rawenv = GetEnvironmentStringsW () ; for (PWCHAR p = rawenv; *p != L'\0'; p = wcschr (p, L'\0') + 1) { + if (wcsncmp (p, L"CYGWIN=", wcslen (L"CYGWIN=")) == 0) + { + PWCHAR q = wcsstr (p, L"error_start") ; + /* replace 'error_start=...' with '_rror_start=...' */ + if (q) + { + *q = L'_' ; + SetEnvironmentVariableW (L"CYGWIN", p + wcslen (L"CYGWIN=")) ; + } + break; + } if (wcsncmp (p, L"MSYS=", wcslen (L"MSYS=")) == 0) { PWCHAR q = wcsstr (p, L"error_start") ; diff --git a/winsup/cygwin/hookapi.cc b/winsup/cygwin/hookapi.cc index 9f31a716c4..49974f8c32 100644 --- a/winsup/cygwin/hookapi.cc +++ b/winsup/cygwin/hookapi.cc @@ -378,13 +378,10 @@ hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys, HANDLE h) // Iterate through each import descriptor, and redirect if appropriate for (PIMAGE_IMPORT_DESCRIPTOR pd = pdfirst; pd->FirstThunk; pd++) { - if (!ascii_strcasematch (rva (PSTR, map ?: (char *) hm, pd->Name - delta), -#ifdef __MSYS__ - "msys-2.0.dll")) -#else - "cygwin1.dll")) -#endif - continue; + char *name_to_compare = rva (PSTR, map ?: (char *) hm, pd->Name - delta); + bool not_msys2 = !ascii_strcasematch (name_to_compare, "msys-2.0.dll"); + bool not_cygwin = !ascii_strcasematch (name_to_compare, "cygwin1.dll"); + if (not_msys2 && not_cygwin) continue; if (!fn) { /* Just checking if executable used cygwin1.dll. */ diff --git a/winsup/utils/mingw/cygcheck.cc b/winsup/utils/mingw/cygcheck.cc index 1637683c26..9f0cb08ab3 100644 --- a/winsup/utils/mingw/cygcheck.cc +++ b/winsup/utils/mingw/cygcheck.cc @@ -95,7 +95,8 @@ static const char *known_env_vars[] = { "c_include_path", "compiler_path", "cxx_include_path", - "msys", + "cygwin", + "cygwin32", "dejagnu", "expect", "gcc_default_options", @@ -107,6 +108,7 @@ static const char *known_env_vars[] = { "lpath", "make_mode", "makeflags", + "msys", "path", "pwd", "strace", diff --git a/winsup/utils/mingw/strace.cc b/winsup/utils/mingw/strace.cc index a6b2e5d548..0eae6f02dd 100644 --- a/winsup/utils/mingw/strace.cc +++ b/winsup/utils/mingw/strace.cc @@ -356,36 +356,21 @@ create_child (char **argv) printf ("create_child: %s\n", one_line.buf); SetConsoleCtrlHandler (NULL, 0); -/* Commit message for this code was: -"* strace.cc (create_child): Set CYGWIN=noglob when starting new process so that - - Cygwin will leave already-parsed the command line alonw." - - I can see no reason for it and it badly breaks the ability to use - strace.exe to investigate calling a Cygwin program from a Windows - program, for example: - strace mingw32-make.exe - .. where mingw32-make.exe finds sh.exe and uses it as the shell. - The reason it badly breaks this use-case is because dcrt0.cc depends - on globbing to happen to parse commandlines from Windows programs; - irrespective of whether they contain any glob patterns or not. - - See quoted () comment: - "This must have been run from a Windows shell, so preserve - quotes for globify to play with later." - - const char *cygwin_env = getenv ("MSYS"); + +#if 0 + const char *cygwin_env = getenv ("CYGWIN"); const char *space; - if (cygwin_env && strlen (cygwin_env) <= 256) // sanity check + if (cygwin_env && strlen (cygwin_env) <= 256) /* sanity check */ space = " "; else space = cygwin_env = ""; - char *newenv = (char *) malloc (sizeof ("MSYS=noglob") + char *newenv = (char *) malloc (sizeof ("CYGWIN=noglob") + strlen (space) + strlen (cygwin_env)); - sprintf (newenv, "MSYS=noglob%s%s", space, cygwin_env); + sprintf (newenv, "CYGWIN=noglob%s%s", space, cygwin_env); _putenv (newenv); -*/ +#endif + ret = CreateProcess (0, one_line.buf, /* command line */ NULL, /* Security */ NULL, /* thread */