summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-06-30 23:01:29 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-06-30 23:01:29 -0700
commitb596ffa6159ddab85dcd182559775c1e84379dee (patch)
tree2df6e635aadcb0649d7d4a9b3a404878761d6cb8
parent3f93f175787bf9ed7bd4902096d2bf8b67c44adc (diff)
downloadcygnal-b596ffa6159ddab85dcd182559775c1e84379dee.tar.gz
cygnal-b596ffa6159ddab85dcd182559775c1e84379dee.tar.bz2
cygnal-b596ffa6159ddab85dcd182559775c1e84379dee.zip
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.
-rw-r--r--winsup/cygwin/include/paths.h2
-rw-r--r--winsup/cygwin/spawn.cc2
-rw-r--r--winsup/cygwin/syscalls.cc56
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 976d32958..ff2d56d39 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -1172,7 +1172,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 6991e0688..707dafd8d 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2638,12 +2638,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)
@@ -4187,9 +4187,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 ()
@@ -4199,58 +4197,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;
}
@@ -4349,8 +4315,8 @@ popen (const char *command, const char *in_type)
const char *argv[4] =
{
- "/bin/sh",
- "-c",
+ _PATH_CMDEXE,
+ "/c",
command,
NULL
};
@@ -4370,8 +4336,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);