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.cc56
1 files changed, 11 insertions, 45 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 6ba4f10f7..c11810741 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -2867,12 +2867,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)
@@ -4412,9 +4412,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 ()
@@ -4424,58 +4422,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;
}
@@ -4574,8 +4540,8 @@ popen (const char *command, const char *in_type)
const char *argv[4] =
{
- "/bin/sh",
- "-c",
+ _PATH_CMDEXE,
+ "/c",
command,
NULL
};
@@ -4595,8 +4561,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);