summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-04 06:26:10 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-04 06:26:10 +0000
commitd80285a9fe71b2e5474c66614d48ad03f0d17d6b (patch)
tree8a12c2fd09f99bd0e889d3fabc4b1fd75527bab9 /win32
parentc471e19f22671662011bc8256e4f942b2ae2fa50 (diff)
* process.c (rb_proc_exec): use same logic as DJGPP on win32 ports.
* process.c (rb_f_system): ditto. * win32/win32.c, win32/win32.h (do_aspawn): [new]. for arrayed arguments. * win32/win32.c (CreateChild): add new argument for real filename of executing process. * win32/win32.c (NtHasRedirection, pipe_exec): follow above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c106
-rw-r--r--win32/win32.h1
2 files changed, 92 insertions, 15 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 6ace011..4b7035b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -88,7 +88,7 @@
bool NtSyncProcess = TRUE;
-static struct ChildRecord *CreateChild(char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
+static struct ChildRecord *CreateChild(char *, char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
static bool NtHasRedirection (char *);
static int valid_filename(char *s);
static void StartSockets ();
@@ -528,7 +528,7 @@ pipe_exec(char *cmd, int mode, FILE **fpr, FILE **fpw)
CloseHandle(hCurProc);
/* create child process */
- child = CreateChild(cmd, &sa, NULL, NULL, NULL);
+ child = CreateChild(cmd, NULL, &sa, NULL, NULL, NULL);
if (!child) {
if (reading) {
SetStdHandle(STD_OUTPUT_HANDLE, hSavedStdOut);
@@ -633,7 +633,76 @@ int
do_spawn(cmd)
char *cmd;
{
- struct ChildRecord *child = CreateChild(cmd, NULL, NULL, NULL, NULL);
+ struct ChildRecord *child = CreateChild(cmd, NULL, NULL, NULL, NULL, NULL);
+ if (!child) {
+ return -1;
+ }
+ rb_syswait(child->pid);
+ return NUM2INT(rb_last_status);
+}
+
+int
+do_aspawn(prog, argv)
+char *prog;
+char **argv;
+{
+ char *cmd, *p, *q, *s, **t;
+ int len, n, bs, quote;
+ struct ChildRecord *child;
+
+ for (t = argv, len = 0; *t; t++) {
+ for (p = *t, n = quote = bs = 0; *p; ++p) {
+ switch (*p) {
+ case '\\':
+ ++bs;
+ break;
+ case '"':
+ n += bs + 1; bs = 0;
+ quote = 1;
+ break;
+ case ' ': case '\t':
+ quote = 1;
+ default:
+ bs = 0;
+ p = CharNext(p) - 1;
+ break;
+ }
+ }
+ len += p - *t + n + 1;
+ if (quote) len += 2;
+ }
+ cmd = ALLOCA_N(char, len);
+ for (t = argv, q = cmd; p = *t; t++) {
+ quote = 0;
+ s = p;
+ if (!*p || strpbrk(p, " \t\"")) {
+ quote = 1;
+ *q++ = '"';
+ }
+ for (bs = 0; *p; ++p) {
+ switch (*p) {
+ case '\\':
+ ++bs;
+ break;
+ case '"':
+ memcpy(q, s, n = p - s); q += n; s = p;
+ memset(q, '\\', ++bs); q += bs; bs = 0;
+ break;
+ default:
+ bs = 0;
+ p = CharNext(p) - 1;
+ break;
+ }
+ }
+ memcpy(q, s, n = p - s);
+ q += n;
+ if (quote) *q++ = '"';
+ *q++ = ' ';
+ }
+ if (q > cmd) --q;
+ *q = '\0';
+
+ child = CreateChild(cmd, prog, NULL, NULL, NULL, NULL);
if (!child) {
return -1;
}
@@ -642,7 +711,7 @@ char *cmd;
}
static struct ChildRecord *
-CreateChild(char *cmd, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput, HANDLE hError)
+CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput, HANDLE hError)
{
BOOL fRet;
DWORD dwCreationFlags;
@@ -692,19 +761,26 @@ CreateChild(char *cmd, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput,
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
- if ((shell = getenv("RUBYSHELL")) && NtHasRedirection(cmd)) {
- char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof (" -c "));
- sprintf(tmp, "%s -c %s", shell, cmd);
- cmd = tmp;
- }
- else if ((shell = getenv("COMSPEC")) &&
- (NtHasRedirection(cmd) || isInternalCmd(cmd))) {
- char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof (" /c "));
- sprintf(tmp, "%s /c %s", shell, cmd);
- cmd = tmp;
+ if (prog) {
+ shell = prog;
}
else {
- shell = NULL;
+ if ((shell = getenv("RUBYSHELL")) && NtHasRedirection(cmd)) {
+ char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) +
+ sizeof (" -c "));
+ sprintf(tmp, "%s -c %s", shell, cmd);
+ cmd = tmp;
+ }
+ else if ((shell = getenv("COMSPEC")) &&
+ (NtHasRedirection(cmd) || isInternalCmd(cmd))) {
+ char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) +
+ sizeof (" /c "));
+ sprintf(tmp, "%s /c %s", shell, cmd);
+ cmd = tmp;
+ }
+ else {
+ shell = NULL;
+ }
}
RUBY_CRITICAL({
diff --git a/win32/win32.h b/win32/win32.h
index b0d03d0..7cdf0a6 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -207,6 +207,7 @@ extern int link(char *, char *);
extern int gettimeofday(struct timeval *, struct timezone *);
extern pid_t waitpid (pid_t, int *, int);
extern int do_spawn(char *);
+extern int do_aspawn(char *, char **);
extern int kill(int, int);
extern pid_t rb_w32_getpid(void);