Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions winsup/cygwin/environ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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 */
Expand Down
11 changes: 11 additions & 0 deletions winsup/cygwin/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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") ;
Expand Down
11 changes: 4 additions & 7 deletions winsup/cygwin/hookapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment on lines +381 to +383
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up until this point, I see the keying factor to be the presence of the MSYS and the CYGWIN environment variable. It is not quite clear what this MR wants to do if both are set, but it is clear that it wants to trigger the MSYS2 vs Cygwin code paths depending on the presence of either environment variable.

This hunk, however, tells a very different story (and one that I could understand much better): whether to run in MSYS2 or in Cygwin mode is keyed by the name of the DLL.

It sounds a bit fraught with peril to have both mechanisms. It would probably be a lot more desirable to key only on one of the two, not on both.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary patch that bootstrap from "msys-2.0.dll" to "cygwin1.dll", once the bootstrap finished. we can then revert this patch directly.

if (not_msys2 && not_cygwin) continue;
if (!fn)
{
/* Just checking if executable used cygwin1.dll. */
Expand Down
4 changes: 3 additions & 1 deletion winsup/utils/mingw/cygcheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -107,6 +108,7 @@ static const char *known_env_vars[] = {
"lpath",
"make_mode",
"makeflags",
"msys",
"path",
"pwd",
"strace",
Expand Down
31 changes: 8 additions & 23 deletions winsup/utils/mingw/strace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment on lines -359 to +373
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of dead code. It would make more sense to investigate properly what the original commit tried to do, why it was wrong, and then to drop that part altogether. But that should most likely come as a separate Merge Request.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do this for reduce MSYS presence in code-base, as it's commted code, so I use #if 0, as this can be accepted, I'll create separte MR for it.

ret = CreateProcess (0, one_line.buf, /* command line */
NULL, /* Security */
NULL, /* thread */
Expand Down
Loading