diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-07-13 06:34:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-26 21:52:24 -0700 |
commit | 4b6150b4b771c19750af76830a49ee32d7ab5c9c (patch) | |
tree | 62ed8f9fee1d2e0b9e4ea2231728d5a63e4c5694 | |
parent | 7fcc8648fca0f4d7a8fb03f8844a4b53cd63bc94 (diff) | |
download | cygnal-4b6150b4b771c19750af76830a49ee32d7ab5c9c.tar.gz cygnal-4b6150b4b771c19750af76830a49ee32d7ab5c9c.tar.bz2 cygnal-4b6150b4b771c19750af76830a49ee32d7ab5c9c.zip |
Implement sh -> cmd.exe translation hack.
* winsup/cygwin/spawn.cc (spawnve): Rewrite /bin/sh -c cmd
invocations to use cmd.exe /c cmd instead.
-rw-r--r-- | winsup/cygwin/spawn.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 4e468d928..253f2fbd1 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -1104,6 +1104,21 @@ spawnve (int mode, const char *path, const char *const *argv, { static char *const empty_env[] = { NULL }; + /* Cygnal hack! If the path is "/bin/sh" and argv is of the three-element + form { "<name>", "-c", "<cmd>" } then let us rewrite argv to: + { "<path-to-cmd.exe>", "/c", "<cmd>" } and invoke "<path-to-cmd.exe>". + This will automatically "port" many programs that use hard-coded /bin/sh + for command execution. For instance, we can use the Cygwin-packaged + gawk.exe binary over Cygnal; awk pipes will work using cmd.exe.*/ + + if (argv[0] && argv[1] && argv[2] && !argv[3] && + !strcmp(path, "/bin/sh") && !strcmp(argv[1], "-c")) + { + const char *argv_sub[3] = { get_cmd_exe_path(), "/c", argv[2] }; + return spawnve (mode, argv_sub[0], + const_cast<const char *const *>(argv_sub), envp); + } + int ret; syscall_printf ("spawnve (%s, %s, %p)", path, argv[0], envp); |