summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--process.c6
-rw-r--r--win32/win32.c106
-rw-r--r--win32/win32.h1
4 files changed, 109 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 696a1200a2..6e22fe5574 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/process.c b/process.c
index 4b855ac3b9..bdf4301290 100644
--- a/process.c
+++ b/process.c
@@ -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 6ace01160e..4b7035b56d 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 b0d03d0902..7cdf0a6319 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);