mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (rb_w32_spawn, rb_w32_aspawn): use NULL as
application name for batch files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5bdeb55a02
commit
6a64e9e4ac
4 changed files with 85 additions and 32 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Mar 22 14:51:55 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_spawn, rb_w32_aspawn): use NULL as
|
||||||
|
application name for batch files.
|
||||||
|
|
||||||
Sat Mar 21 15:54:41 2009 Tanaka Akira <akr@fsij.org>
|
Sat Mar 21 15:54:41 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_ssl.c (write_would_block): defined.
|
* ext/openssl/ossl_ssl.c (write_would_block): defined.
|
||||||
|
|
|
@ -824,6 +824,15 @@ class TestProcess < Test::Unit::TestCase
|
||||||
assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1)
|
assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1)
|
||||||
assert_match(/\Ataki pid=\d+ ppid=\d+\z/, result2)
|
assert_match(/\Ataki pid=\d+ ppid=\d+\z/, result2)
|
||||||
assert_not_equal(result1[/\d+/].to_i, status.pid)
|
assert_not_equal(result1[/\d+/].to_i, status.pid)
|
||||||
|
|
||||||
|
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
Dir.mkdir(path = "path with space")
|
||||||
|
write_file(bat = path + "/bat test.bat", "@echo %1>out")
|
||||||
|
system(bat, "foo 'bar'")
|
||||||
|
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||||
|
system(%[#{bat.dump} "foo 'bar'"])
|
||||||
|
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -847,6 +856,23 @@ class TestProcess < Test::Unit::TestCase
|
||||||
assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1)
|
assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1)
|
||||||
assert_match(/\Atake pid=\d+ ppid=\d+\z/, result2)
|
assert_match(/\Atake pid=\d+ ppid=\d+\z/, result2)
|
||||||
assert_not_equal(result1[/\d+/].to_i, status.pid)
|
assert_not_equal(result1[/\d+/].to_i, status.pid)
|
||||||
|
|
||||||
|
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
Dir.mkdir(path = "path with space")
|
||||||
|
write_file(bat = path + "/bat test.bat", "@echo %1>out")
|
||||||
|
pid = spawn(bat, "foo 'bar'")
|
||||||
|
Process.wait pid
|
||||||
|
status = $?
|
||||||
|
assert(status.exited?)
|
||||||
|
assert(status.success?)
|
||||||
|
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||||
|
pid = spawn(%[#{bat.dump} "foo 'bar'"])
|
||||||
|
Process.wait pid
|
||||||
|
status = $?
|
||||||
|
assert(status.exited?)
|
||||||
|
assert(status.success?)
|
||||||
|
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -871,9 +897,11 @@ class TestProcess < Test::Unit::TestCase
|
||||||
|
|
||||||
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
|
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
|
||||||
Dir.mkdir(path = "path with space")
|
Dir.mkdir(path = "path with space")
|
||||||
write_file(bat = path + "/battest.bat", "@echo %1")
|
write_file(bat = path + "/bat test.bat", "@echo %1")
|
||||||
r = IO.popen([bat, "foo 'bar'"]) {|f| f.read}
|
r = IO.popen([bat, "foo 'bar'"]) {|f| f.read}
|
||||||
assert_equal(%["foo 'bar'"\n], r, '[ruby-core:22960]')
|
assert_equal(%["foo 'bar'"\n], r, '[ruby-core:22960]')
|
||||||
|
r = IO.popen(%[#{bat.dump} "foo 'bar'"]) {|f| f.read}
|
||||||
|
assert_equal(%["foo 'bar'"\n], r, '[ruby-core:22960]')
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define RUBY_VERSION "1.9.2"
|
#define RUBY_VERSION "1.9.2"
|
||||||
#define RUBY_RELEASE_DATE "2009-03-21"
|
#define RUBY_RELEASE_DATE "2009-03-22"
|
||||||
#define RUBY_PATCHLEVEL -1
|
#define RUBY_PATCHLEVEL -1
|
||||||
#define RUBY_BRANCH_NAME "trunk"
|
#define RUBY_BRANCH_NAME "trunk"
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
#define RUBY_RELEASE_YEAR 2009
|
#define RUBY_RELEASE_YEAR 2009
|
||||||
#define RUBY_RELEASE_MONTH 3
|
#define RUBY_RELEASE_MONTH 3
|
||||||
#define RUBY_RELEASE_DAY 21
|
#define RUBY_RELEASE_DAY 22
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
|
|
@ -1005,6 +1005,18 @@ CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
is_batch(const char *cmd)
|
||||||
|
{
|
||||||
|
int len = strlen(cmd);
|
||||||
|
if (len <= 4) return 0;
|
||||||
|
cmd += len - 4;
|
||||||
|
if (*cmd++ != '.') return 0;
|
||||||
|
if (strcasecmp(cmd, "bat") == 0) return 1;
|
||||||
|
if (strcasecmp(cmd, "cmd") == 0) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
rb_pid_t
|
rb_pid_t
|
||||||
rb_w32_spawn(int mode, const char *cmd, const char *prog)
|
rb_w32_spawn(int mode, const char *cmd, const char *prog)
|
||||||
{
|
{
|
||||||
|
@ -1043,27 +1055,21 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int len = 0, quote = (*cmd == '"') ? '"' : 0;
|
int len = 0, quote = (*cmd == '"') ? '"' : 0;
|
||||||
shell = NULL;
|
const char *comspec = shell;
|
||||||
for (prog = cmd + !!quote;; prog = CharNext(prog)) {
|
for (prog = cmd + !!quote;; prog = CharNext(prog)) {
|
||||||
if (!*prog) {
|
if (!*prog) {
|
||||||
len = prog - cmd;
|
len = prog - cmd;
|
||||||
shell = cmd;
|
shell = cmd;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*prog == quote) {
|
if ((unsigned char)*prog == quote) {
|
||||||
len = prog++ - cmd - 1;
|
len = prog++ - cmd - 1;
|
||||||
STRNDUPA(p, cmd + 1, len);
|
STRNDUPA(p, cmd + 1, len);
|
||||||
shell = p;
|
shell = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (quote) continue;
|
if (quote) continue;
|
||||||
if (strchr("*?\"", *prog)) {
|
if (ISSPACE(*prog) || strchr("<>|*?\"", *prog)) {
|
||||||
len = prog - cmd;
|
|
||||||
STRNDUPA(p, cmd, len);
|
|
||||||
shell = p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (ISSPACE(*prog) || strchr("<>|", *prog)) {
|
|
||||||
len = prog - cmd;
|
len = prog - cmd;
|
||||||
STRNDUPA(p, cmd, len);
|
STRNDUPA(p, cmd, len);
|
||||||
shell = p;
|
shell = p;
|
||||||
|
@ -1071,18 +1077,31 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shell = dln_find_exe_r(shell, NULL, fbuf, sizeof(fbuf));
|
shell = dln_find_exe_r(shell, NULL, fbuf, sizeof(fbuf));
|
||||||
if (shell == fbuf) {
|
if (!shell) {
|
||||||
len += strlen(prog) + (quote ? 2 : 0) + 1;
|
shell = comspec;
|
||||||
cmd = p = ALLOCA_N(char, len);
|
|
||||||
if (quote) *p++ = '"';
|
|
||||||
p += strlcpy(p, fbuf, --len);
|
|
||||||
if (quote) *p++ = '"';
|
|
||||||
p += strlcpy(p, prog, --len);
|
|
||||||
if (quote) shell = NULL;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
len = strlen(shell);
|
||||||
|
if (strchr(shell, ' ')) quote = -1;
|
||||||
|
if (shell == fbuf) {
|
||||||
|
p = fbuf;
|
||||||
|
}
|
||||||
|
else if (shell != p && strchr(shell, '/')) {
|
||||||
|
STRNDUPA(p, shell, len);
|
||||||
shell = p;
|
shell = p;
|
||||||
}
|
}
|
||||||
|
if (p) translate_char(p, '/', '\\');
|
||||||
|
if (is_batch(shell)) {
|
||||||
|
int alen = strlen(prog);
|
||||||
|
cmd = p = ALLOCA_N(char, len + alen + (quote ? 2 : 0) + 1);
|
||||||
|
if (quote) *p++ = '"';
|
||||||
|
memcpy(p, shell, len);
|
||||||
|
p += len;
|
||||||
|
if (quote) *p++ = '"';
|
||||||
|
memcpy(p, prog, alen + 1);
|
||||||
|
shell = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1092,7 +1111,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
|
||||||
rb_pid_t
|
rb_pid_t
|
||||||
rb_w32_aspawn(int mode, const char *prog, char *const *argv)
|
rb_w32_aspawn(int mode, const char *prog, char *const *argv)
|
||||||
{
|
{
|
||||||
int len, differ = 0, c_switch = 0;
|
int len, c_switch = 0;
|
||||||
BOOL ntcmd = FALSE, tmpnt;
|
BOOL ntcmd = FALSE, tmpnt;
|
||||||
const char *shell;
|
const char *shell;
|
||||||
char *cmd, fbuf[MAXPATHLEN];
|
char *cmd, fbuf[MAXPATHLEN];
|
||||||
|
@ -1105,40 +1124,41 @@ rb_w32_aspawn(int mode, const char *prog, char *const *argv)
|
||||||
ntcmd = tmpnt;
|
ntcmd = tmpnt;
|
||||||
prog = shell;
|
prog = shell;
|
||||||
c_switch = 1;
|
c_switch = 1;
|
||||||
differ = 1;
|
|
||||||
}
|
}
|
||||||
else if ((cmd = dln_find_exe_r(prog, NULL, fbuf, sizeof(fbuf)))) {
|
else if ((cmd = dln_find_exe_r(prog, NULL, fbuf, sizeof(fbuf)))) {
|
||||||
if (cmd == prog) strlcpy(cmd = fbuf, prog, sizeof(fbuf));
|
if (cmd == prog) strlcpy(cmd = fbuf, prog, sizeof(fbuf));
|
||||||
translate_char(cmd, '/', '\\');
|
translate_char(cmd, '/', '\\');
|
||||||
prog = cmd;
|
prog = cmd;
|
||||||
argv++;
|
|
||||||
differ = 1;
|
|
||||||
}
|
}
|
||||||
else if (strchr(prog, '/')) {
|
else if (strchr(prog, '/')) {
|
||||||
strlcpy(fbuf, prog, sizeof(fbuf));
|
len = strlen(prog);
|
||||||
translate_char(fbuf, '/', '\\');
|
if (len < sizeof(fbuf))
|
||||||
prog = fbuf;
|
strlcpy(cmd = fbuf, prog, sizeof(fbuf));
|
||||||
argv++;
|
else
|
||||||
differ = 1;
|
STRNDUPA(cmd, prog, len);
|
||||||
|
translate_char(cmd, '/', '\\');
|
||||||
|
prog = cmd;
|
||||||
}
|
}
|
||||||
if (differ) {
|
if (c_switch || is_batch(prog)) {
|
||||||
char *progs[2];
|
char *progs[2];
|
||||||
progs[0] = (char *)prog;
|
progs[0] = (char *)prog;
|
||||||
progs[1] = NULL;
|
progs[1] = NULL;
|
||||||
len = argv_size(progs, ntcmd);
|
len = argv_size(progs, ntcmd);
|
||||||
if (c_switch) len += 3;
|
if (c_switch) len += 3;
|
||||||
|
else ++argv;
|
||||||
if (argv[0]) len += argv_size(argv, ntcmd);
|
if (argv[0]) len += argv_size(argv, ntcmd);
|
||||||
cmd = ALLOCA_N(char, len);
|
cmd = ALLOCA_N(char, len);
|
||||||
join_argv(cmd, progs, ntcmd);
|
join_argv(cmd, progs, ntcmd);
|
||||||
if (c_switch) strlcat(cmd, " /c", len);
|
if (c_switch) strlcat(cmd, " /c", len);
|
||||||
if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd);
|
if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd);
|
||||||
prog = 0;
|
prog = c_switch ? shell : 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len = argv_size(argv, FALSE);
|
len = argv_size(argv, FALSE);
|
||||||
cmd = ALLOCA_N(char, len);
|
cmd = ALLOCA_N(char, len);
|
||||||
join_argv(cmd, argv, FALSE);
|
join_argv(cmd, argv, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return child_result(CreateChild(cmd, prog, NULL, NULL, NULL, NULL), mode);
|
return child_result(CreateChild(cmd, prog, NULL, NULL, NULL, NULL), mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue