Skip to content

Commit

Permalink
strace.cc: Don't set MSYS=noglob
Browse files Browse the repository at this point in the history
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."
  • Loading branch information
mingwandroid authored and dscho committed May 13, 2022
1 parent bb5f409 commit e93812d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion winsup/utils/mingw/strace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,36 @@ create_child (char **argv)
make_command_line (one_line, argv);

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");
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")
+ strlen (space) + strlen (cygwin_env));
sprintf (newenv, "MSYS=noglob%s%s", space, cygwin_env);
_putenv (newenv);
*/
ret = CreateProcess (0, one_line.buf, /* command line */
NULL, /* Security */
NULL, /* thread */
Expand Down

0 comments on commit e93812d

Please sign in to comment.