diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-04 06:26:10 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-04 06:26:10 +0000 |
commit | 142592a2eddbe959a3ff89bae5856ff416f2d821 (patch) | |
tree | 8a12c2fd09f99bd0e889d3fabc4b1fd75527bab9 | |
parent | 2dad828a89001002da36d492d1631b2476af6756 (diff) | |
download | ruby-142592a2eddbe959a3ff89bae5856ff416f2d821.tar.gz ruby-142592a2eddbe959a3ff89bae5856ff416f2d821.tar.xz ruby-142592a2eddbe959a3ff89bae5856ff416f2d821.zip |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@3283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | process.c | 6 | ||||
-rw-r--r-- | win32/win32.c | 106 | ||||
-rw-r--r-- | win32/win32.h | 1 |
4 files changed, 109 insertions, 18 deletions
@@ -1,3 +1,17 @@ +Sat Jan 4 15:18:50 2003 NAKAMURA Usaku <usa@ruby-lang.org> + + * 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. + Sat Jan 4 14:29:52 2003 NAKAMURA Usaku <usa@ruby-lang.org> * configure.in: set rb_cv_need_io_flush_between_seek=yes. @@ -577,7 +577,7 @@ rb_proc_exec(str) return -1; } -#if defined(__human68k__) || defined(__DJGPP__) +#if defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32) static int proc_spawn_v(argv, prog) char **argv; @@ -814,7 +814,7 @@ rb_f_system(argc, argv) int argc; VALUE *argv; { -#if defined(_WIN32) || defined(__EMX__) +#if defined(__EMX__) VALUE cmd; int status; @@ -839,7 +839,7 @@ rb_f_system(argc, argv) if (status == 0) return Qtrue; return Qfalse; -#elif defined(__human68k__) || defined(__DJGPP__) +#elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32) volatile VALUE prog = 0; int status; diff --git a/win32/win32.c b/win32/win32.c index 6ace01160..4b7035b56 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 b0d03d090..7cdf0a631 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); |