* 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
This commit is contained in:
parent
c471e19f22
commit
d80285a9fe
14
ChangeLog
14
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>
|
Sat Jan 4 14:29:52 2003 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: set rb_cv_need_io_flush_between_seek=yes.
|
* configure.in: set rb_cv_need_io_flush_between_seek=yes.
|
||||||
|
@ -577,7 +577,7 @@ rb_proc_exec(str)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__human68k__) || defined(__DJGPP__)
|
#if defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32)
|
||||||
static int
|
static int
|
||||||
proc_spawn_v(argv, prog)
|
proc_spawn_v(argv, prog)
|
||||||
char **argv;
|
char **argv;
|
||||||
@ -814,7 +814,7 @@ rb_f_system(argc, argv)
|
|||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(__EMX__)
|
#if defined(__EMX__)
|
||||||
VALUE cmd;
|
VALUE cmd;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -839,7 +839,7 @@ rb_f_system(argc, argv)
|
|||||||
|
|
||||||
if (status == 0) return Qtrue;
|
if (status == 0) return Qtrue;
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
#elif defined(__human68k__) || defined(__DJGPP__)
|
#elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32)
|
||||||
volatile VALUE prog = 0;
|
volatile VALUE prog = 0;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
bool NtSyncProcess = TRUE;
|
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 bool NtHasRedirection (char *);
|
||||||
static int valid_filename(char *s);
|
static int valid_filename(char *s);
|
||||||
static void StartSockets ();
|
static void StartSockets ();
|
||||||
@ -528,7 +528,7 @@ pipe_exec(char *cmd, int mode, FILE **fpr, FILE **fpw)
|
|||||||
CloseHandle(hCurProc);
|
CloseHandle(hCurProc);
|
||||||
|
|
||||||
/* create child process */
|
/* create child process */
|
||||||
child = CreateChild(cmd, &sa, NULL, NULL, NULL);
|
child = CreateChild(cmd, NULL, &sa, NULL, NULL, NULL);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
if (reading) {
|
if (reading) {
|
||||||
SetStdHandle(STD_OUTPUT_HANDLE, hSavedStdOut);
|
SetStdHandle(STD_OUTPUT_HANDLE, hSavedStdOut);
|
||||||
@ -633,7 +633,76 @@ int
|
|||||||
do_spawn(cmd)
|
do_spawn(cmd)
|
||||||
char *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) {
|
if (!child) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -642,7 +711,7 @@ char *cmd;
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct ChildRecord *
|
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;
|
BOOL fRet;
|
||||||
DWORD dwCreationFlags;
|
DWORD dwCreationFlags;
|
||||||
@ -692,20 +761,27 @@ CreateChild(char *cmd, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput,
|
|||||||
|
|
||||||
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
|
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
|
||||||
|
|
||||||
|
if (prog) {
|
||||||
|
shell = prog;
|
||||||
|
}
|
||||||
|
else {
|
||||||
if ((shell = getenv("RUBYSHELL")) && NtHasRedirection(cmd)) {
|
if ((shell = getenv("RUBYSHELL")) && NtHasRedirection(cmd)) {
|
||||||
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof (" -c "));
|
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) +
|
||||||
|
sizeof (" -c "));
|
||||||
sprintf(tmp, "%s -c %s", shell, cmd);
|
sprintf(tmp, "%s -c %s", shell, cmd);
|
||||||
cmd = tmp;
|
cmd = tmp;
|
||||||
}
|
}
|
||||||
else if ((shell = getenv("COMSPEC")) &&
|
else if ((shell = getenv("COMSPEC")) &&
|
||||||
(NtHasRedirection(cmd) || isInternalCmd(cmd))) {
|
(NtHasRedirection(cmd) || isInternalCmd(cmd))) {
|
||||||
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + sizeof (" /c "));
|
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) +
|
||||||
|
sizeof (" /c "));
|
||||||
sprintf(tmp, "%s /c %s", shell, cmd);
|
sprintf(tmp, "%s /c %s", shell, cmd);
|
||||||
cmd = tmp;
|
cmd = tmp;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shell = NULL;
|
shell = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
fRet = CreateProcess(shell, cmd, psa, psa,
|
fRet = CreateProcess(shell, cmd, psa, psa,
|
||||||
|
@ -207,6 +207,7 @@ extern int link(char *, char *);
|
|||||||
extern int gettimeofday(struct timeval *, struct timezone *);
|
extern int gettimeofday(struct timeval *, struct timezone *);
|
||||||
extern pid_t waitpid (pid_t, int *, int);
|
extern pid_t waitpid (pid_t, int *, int);
|
||||||
extern int do_spawn(char *);
|
extern int do_spawn(char *);
|
||||||
|
extern int do_aspawn(char *, char **);
|
||||||
extern int kill(int, int);
|
extern int kill(int, int);
|
||||||
extern pid_t rb_w32_getpid(void);
|
extern pid_t rb_w32_getpid(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user