summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/spawn.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r--winsup/cygwin/spawn.cc27
1 files changed, 26 insertions, 1 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index ec0272739..d611b2cd0 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -13,7 +13,9 @@ details. */
#include <sys/wait.h>
#include <wchar.h>
#include <ctype.h>
+#include <stdio.h>
#include <sys/cygwin.h>
+#include <pthread.h>
#include "cygerrno.h"
#include "security.h"
#include "sigproc.h"
@@ -1178,7 +1180,7 @@ av::setup (const char *prog_arg, path_conv& real_path, const char *ext,
}
if (ascii_strcasematch (ext, ".com"))
break;
- if ((pgm = getenv("COMSPEC")) == NULL) {
+ if ((pgm = const_cast<char *>(get_cmd_exe_path())) == NULL) {
set_errno (EOPNOTSUPP);
return -1;
}
@@ -1213,3 +1215,26 @@ err:
__seterrno ();
return -1;
}
+
+static const char *cmd_exe_path = NULL;
+
+static void init_cmd_exe_path(void)
+{
+ char sysdir[NT_MAX_PATH];
+ char cmdname[] = "cmd.exe";
+ unsigned int nchars;
+
+ if ((nchars = GetSystemDirectoryA(sysdir, sizeof sysdir)) < sizeof sysdir) {
+ unsigned int total = nchars + 1 + sizeof cmdname + 1;
+ char *path = static_cast<char *>(cmalloc_abort(HEAP_STR, total));
+ snprintf(path, total, "%s\\%s", sysdir, cmdname);
+ cmd_exe_path = path;
+ }
+}
+
+const char *get_cmd_exe_path()
+{
+ static pthread_once_t cmd_exe_once = PTHREAD_ONCE_INIT;
+ pthread_once (&cmd_exe_once, init_cmd_exe_path);
+ return cmd_exe_path;
+}