From ed0e3b0f38df5d4da54f0d785c29b9f40592fb80 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 30 Jun 2016 23:01:29 -0700 Subject: Cygnal apps use cmd.exe, not /bin/sh. * winsup/cygwin/include/paths.h (_PATH_CMDEXE): New preprocessor symbol. * winsup/cygwin/spawn.cc (av_setup): Use _PATH_CMDEXE rather than "/bin/sh". * winsup/cygwin/syscalls.cc (system): Spawn _PATH_CMDEXE with /c option rather than /bin/sh. (ETC_SHELLS): Preprocessor symbol removed. (shell_fp): Global variable removed. (getusershell): Don't open ETC_SHELLS, just march through static array of shell names. That array contains only one entry: _PATH_CMDEXE. (setusershell, endusershell): Remove references to shell_fp. (popen): Exec _PATH_CMDEXE rather than "/bin/sh", and the option is /c. --- winsup/cygwin/include/paths.h | 2 +- winsup/cygwin/spawn.cc | 2 +- winsup/cygwin/syscalls.cc | 56 +++++++++---------------------------------- 3 files changed, 13 insertions(+), 47 deletions(-) diff --git a/winsup/cygwin/include/paths.h b/winsup/cygwin/include/paths.h index a21591f64..cf25056d8 100644 --- a/winsup/cygwin/include/paths.h +++ b/winsup/cygwin/include/paths.h @@ -29,5 +29,5 @@ details. */ #define _PATH_VARTMP "/var/tmp/" #define _PATH_VI "/bin/vi" #define _PATH_WTMP "/var/log/wtmp" - +#define _PATH_CMDEXE "C:/Windows/System32/cmd.exe" #endif /* _PATHS_H_ */ diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 87137cd03..05020952a 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -1160,7 +1160,7 @@ av::setup (const char *prog_arg, path_conv& real_path, const char *ext, } if (ascii_strcasematch (ext, ".com")) break; - pgm = (char *) "/bin/sh"; + pgm = (char *) _PATH_CMDEXE; arg1 = NULL; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 61872fe58..db5411fff 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2620,12 +2620,12 @@ system (const char *cmdstring) __try { - command[0] = "sh"; - command[1] = "-c"; + command[0] = _PATH_CMDEXE; + command[1] = "/c"; command[2] = cmdstring; command[3] = (const char *) NULL; - if ((res = spawnvp (_P_SYSTEM, "/bin/sh", command)) == -1) + if ((res = spawnvp (_P_SYSTEM, _PATH_CMDEXE, command)) == -1) { // when exec fails, return value should be as if shell // executed exit (127) @@ -4147,9 +4147,7 @@ gethostid (void) return (int32_t) hostid; /* Avoid sign extension. */ } -#define ETC_SHELLS "/etc/shells" static int shell_index; -static struct __sFILE64 *shell_fp; extern "C" char * getusershell () @@ -4159,58 +4157,26 @@ getusershell () might be shipped with the OS. Should we do the same for the Cygwin distro, adding bash, tcsh, ksh, pdksh and zsh? */ static const char *def_shells[] = { - "/bin/sh", - "/bin/csh", - "/usr/bin/sh", - "/usr/bin/csh", + _PATH_CMDEXE, NULL }; + static char buf[PATH_MAX]; - int ch, buf_idx; - if (!shell_fp && !(shell_fp = fopen64 (ETC_SHELLS, "rt"))) - { - if (def_shells[shell_index]) - return strcpy (buf, def_shells[shell_index++]); - return NULL; - } - /* Skip white space characters. */ - while ((ch = getc (shell_fp)) != EOF && isspace (ch)) - ; - /* Get each non-whitespace character as part of the shell path as long as - it fits in buf. */ - for (buf_idx = 0; - ch != EOF && !isspace (ch) && buf_idx < (PATH_MAX - 1); - buf_idx++, ch = getc (shell_fp)) - buf[buf_idx] = ch; - /* Skip any trailing non-whitespace character not fitting in buf. If the - path is longer than PATH_MAX, it's invalid anyway. */ - while (ch != EOF && !isspace (ch)) - ch = getc (shell_fp); - if (buf_idx) - { - buf[buf_idx] = '\0'; - return buf; - } + if (def_shells[shell_index]) + return strcpy (buf, def_shells[shell_index++]); return NULL; } extern "C" void setusershell () { - if (shell_fp) - fseek (shell_fp, 0L, SEEK_SET); shell_index = 0; } extern "C" void endusershell () { - if (shell_fp) - { - fclose (shell_fp); - shell_fp = NULL; - } shell_index = 0; } @@ -4309,8 +4275,8 @@ popen (const char *command, const char *in_type) const char *argv[4] = { - "/bin/sh", - "-c", + _PATH_CMDEXE, + "/c", command, NULL }; @@ -4330,8 +4296,8 @@ popen (const char *command, const char *in_type) fcntl64 (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC); /* Start a shell process to run the given command without forking. */ - pid_t pid = ch_spawn.worker ("/bin/sh", argv, cur_environ (), _P_NOWAIT, - __std[0], __std[1]); + pid_t pid = ch_spawn.worker (_PATH_CMDEXE, argv, cur_environ (), + _P_NOWAIT, __std[0], __std[1]); /* Reinstate the close-on-exec state */ fcntl64 (stdchild, F_SETFD, stdchild_state); -- cgit v1.2.3