summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/syscalls.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc38
1 files changed, 21 insertions, 17 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 707dafd8d..b238b6e64 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2635,15 +2635,19 @@ system (const char *cmdstring)
int res = -1;
const char* command[4];
+ const char *cmdexe = getenv("COMSPEC");
+
+ if (cmdexe == NULL)
+ return res;
__try
{
- command[0] = _PATH_CMDEXE;
+ command[0] = cmdexe;
command[1] = "/c";
command[2] = cmdstring;
command[3] = (const char *) NULL;
- if ((res = spawnvp (_P_SYSTEM, _PATH_CMDEXE, command)) == -1)
+ if ((res = spawnvp (_P_SYSTEM, cmdexe, command)) == -1)
{
// when exec fails, return value should be as if shell
// executed exit (127)
@@ -4192,19 +4196,13 @@ static int shell_index;
extern "C" char *
getusershell ()
{
- /* List of default shells if no /etc/shells exists, defined as on Linux.
- FIXME: SunOS has a far longer list, containing all shells which
- 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[] = {
- _PATH_CMDEXE,
- NULL
- };
-
- static char buf[PATH_MAX];
-
- if (def_shells[shell_index])
- return strcpy (buf, def_shells[shell_index++]);
+ if (shell_index == 0) {
+ char *cmdexe = getenv("COMSPEC");
+ if (cmdexe != NULL) {
+ shell_index = 1;
+ return cmdexe;
+ }
+ }
return NULL;
}
@@ -4244,10 +4242,16 @@ popen (const char *command, const char *in_type)
const char *type = in_type;
char fdopen_flags[3] = "\0\0";
int pipe_flags = 0;
+ const char *cmdexe = getenv("COMSPEC");
#define rw fdopen_flags[0]
#define bintext fdopen_flags[1]
+ if (cmdexe == NULL) {
+ set_errno (EOPNOTSUPP);
+ return NULL;
+ }
+
/* Sanity check. GLibc allows any order and any number of repetition,
as long as the string doesn't contradict itself. We do the same here. */
while (*type)
@@ -4315,7 +4319,7 @@ popen (const char *command, const char *in_type)
const char *argv[4] =
{
- _PATH_CMDEXE,
+ cmdexe,
"/c",
command,
NULL
@@ -4336,7 +4340,7 @@ 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 (_PATH_CMDEXE, argv, cur_environ (),
+ pid_t pid = ch_spawn.worker (cmdexe, argv, cur_environ (),
_P_NOWAIT, __std[0], __std[1]);
/* Reinstate the close-on-exec state */