posix-spawn 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/extconf.rb +6 -1
- data/ext/posix-spawn.c +10 -2
- data/lib/posix/spawn.rb +34 -1
- data/lib/posix/spawn/version.rb +1 -1
- data/test/test_backtick.rb +10 -10
- data/test/test_child.rb +2 -0
- data/test/test_popen.rb +2 -2
- data/test/test_spawn.rb +6 -6
- data/test/test_system.rb +7 -7
- metadata +5 -5
data/ext/extconf.rb
CHANGED
data/ext/posix-spawn.c
CHANGED
@@ -69,14 +69,22 @@ posixspawn_obj_to_fd(VALUE obj)
|
|
69
69
|
|
70
70
|
case T_FILE:
|
71
71
|
/* IO object */
|
72
|
-
|
72
|
+
if (rb_respond_to(obj, rb_intern("posix_fileno"))) {
|
73
|
+
fd = FIX2INT(rb_funcall(obj, rb_intern("posix_fileno"), 0));
|
74
|
+
} else {
|
75
|
+
fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
|
76
|
+
}
|
73
77
|
break;
|
74
78
|
|
75
79
|
case T_OBJECT:
|
76
80
|
/* some other object */
|
77
81
|
if (rb_respond_to(obj, rb_intern("to_io"))) {
|
78
82
|
obj = rb_funcall(obj, rb_intern("to_io"), 0);
|
79
|
-
|
83
|
+
if (rb_respond_to(obj, rb_intern("posix_fileno"))) {
|
84
|
+
fd = FIX2INT(rb_funcall(obj, rb_intern("posix_fileno"), 0));
|
85
|
+
} else {
|
86
|
+
fd = FIX2INT(rb_funcall(obj, rb_intern("fileno"), 0));
|
87
|
+
}
|
80
88
|
}
|
81
89
|
break;
|
82
90
|
}
|
data/lib/posix/spawn.rb
CHANGED
@@ -1,7 +1,30 @@
|
|
1
|
-
|
1
|
+
unless RUBY_PLATFORM =~ /(mswin|mingw|bccwin)/
|
2
|
+
require 'posix_spawn_ext'
|
3
|
+
end
|
4
|
+
|
2
5
|
require 'posix/spawn/version'
|
3
6
|
require 'posix/spawn/child'
|
4
7
|
|
8
|
+
class IO
|
9
|
+
if defined? JRUBY_VERSION
|
10
|
+
require 'jruby'
|
11
|
+
def posix_fileno
|
12
|
+
case self
|
13
|
+
when STDIN, $stdin
|
14
|
+
0
|
15
|
+
when STDOUT, $stdout
|
16
|
+
1
|
17
|
+
when STDERR, $stderr
|
18
|
+
2
|
19
|
+
else
|
20
|
+
JRuby.reference(self).getOpenFile.getMainStream.getDescriptor.getChannel.getFDVal
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
alias :posix_fileno :fileno
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
5
28
|
module POSIX
|
6
29
|
# The POSIX::Spawn module implements a compatible subset of Ruby 1.9's
|
7
30
|
# Process::spawn and related methods using the IEEE Std 1003.1 posix_spawn(2)
|
@@ -151,6 +174,16 @@ module POSIX
|
|
151
174
|
def pspawn(*args)
|
152
175
|
env, argv, options = extract_process_spawn_arguments(*args)
|
153
176
|
raise NotImplementedError unless respond_to?(:_pspawn)
|
177
|
+
|
178
|
+
if defined? JRUBY_VERSION
|
179
|
+
# On the JVM, changes made to the environment are not propagated down
|
180
|
+
# to C via get/setenv, so we have to fake it here.
|
181
|
+
unless options[:unsetenv_others] == true
|
182
|
+
env = ENV.merge(env)
|
183
|
+
options[:unsetenv_others] = true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
154
187
|
_pspawn(env, argv, options)
|
155
188
|
end
|
156
189
|
|
data/lib/posix/spawn/version.rb
CHANGED
data/test/test_backtick.rb
CHANGED
@@ -6,31 +6,31 @@ class BacktickTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def test_backtick_simple
|
8
8
|
out = `exit`
|
9
|
-
assert_equal
|
10
|
-
assert_equal $?.exitstatus
|
9
|
+
assert_equal '', out
|
10
|
+
assert_equal 0, $?.exitstatus
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_backtick_output
|
14
14
|
out = `echo 123`
|
15
|
-
assert_equal
|
16
|
-
assert_equal $?.exitstatus, 0
|
15
|
+
assert_equal "123\n", out
|
16
|
+
assert_equal 0, $?.exitstatus, 0
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_backtick_failure
|
20
20
|
out = `nosuchcmd 2> /dev/null`
|
21
|
-
assert_equal
|
22
|
-
assert_equal $?.exitstatus
|
21
|
+
assert_equal '', out
|
22
|
+
assert_equal 127, $?.exitstatus
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_backtick_redirect
|
26
26
|
out = `nosuchcmd 2>&1`
|
27
|
-
assert_equal
|
28
|
-
assert_equal $?.exitstatus, 127
|
27
|
+
assert_equal "/bin/sh: nosuchcmd: command not found\n", out
|
28
|
+
assert_equal 127, $?.exitstatus, 127
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_backtick_huge
|
32
32
|
out = `yes | head -50000`
|
33
|
-
assert_equal out.size
|
34
|
-
assert_equal $?.exitstatus
|
33
|
+
assert_equal 100000, out.size
|
34
|
+
assert_equal 0, $?.exitstatus
|
35
35
|
end
|
36
36
|
end
|
data/test/test_child.rb
CHANGED
@@ -75,9 +75,11 @@ class ChildTest < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_timeout
|
78
|
+
start = Time.now
|
78
79
|
assert_raise TimeoutExceeded do
|
79
80
|
Child.new('sleep', '1', :timeout => 0.05)
|
80
81
|
end
|
82
|
+
assert (Time.now-start) <= 0.2
|
81
83
|
end
|
82
84
|
|
83
85
|
def test_timeout_with_child_hierarchy
|
data/test/test_popen.rb
CHANGED
@@ -10,8 +10,8 @@ class PopenTest < Test::Unit::TestCase
|
|
10
10
|
i.close
|
11
11
|
::Process.wait(pid)
|
12
12
|
|
13
|
-
assert_equal
|
14
|
-
assert_equal $?.exitstatus
|
13
|
+
assert_equal "hello world", o.read
|
14
|
+
assert_equal 0, $?.exitstatus
|
15
15
|
ensure
|
16
16
|
[i, o, e].each{ |io| io.close rescue nil }
|
17
17
|
end
|
data/test/test_spawn.rb
CHANGED
@@ -68,7 +68,7 @@ module SpawnImplementationTests
|
|
68
68
|
|
69
69
|
def test_sanity_of_checking_clone_with_sh
|
70
70
|
rd, wr = IO.pipe
|
71
|
-
pid = _spawn("exec 2>/dev/null 100<&#{rd.
|
71
|
+
pid = _spawn("exec 2>/dev/null 100<&#{rd.posix_fileno} || exit 1", rd => rd)
|
72
72
|
assert_process_exit_status pid, 0
|
73
73
|
ensure
|
74
74
|
[rd, wr].each { |fd| fd.close rescue nil }
|
@@ -94,7 +94,7 @@ module SpawnImplementationTests
|
|
94
94
|
|
95
95
|
def test_spawn_close_option_with_fd_number
|
96
96
|
rd, wr = IO.pipe
|
97
|
-
pid = _spawn("exec 2>/dev/null 100<&#{rd.
|
97
|
+
pid = _spawn("exec 2>/dev/null 100<&#{rd.posix_fileno} || exit 1", rd.posix_fileno => :close)
|
98
98
|
assert_process_exit_status pid, 1
|
99
99
|
|
100
100
|
assert !rd.closed?
|
@@ -105,7 +105,7 @@ module SpawnImplementationTests
|
|
105
105
|
|
106
106
|
def test_spawn_close_option_with_io_object
|
107
107
|
rd, wr = IO.pipe
|
108
|
-
pid = _spawn("exec 2>/dev/null 100<&#{rd.
|
108
|
+
pid = _spawn("exec 2>/dev/null 100<&#{rd.posix_fileno} || exit 1", rd => :close)
|
109
109
|
assert_process_exit_status pid, 1
|
110
110
|
|
111
111
|
assert !rd.closed?
|
@@ -123,7 +123,7 @@ module SpawnImplementationTests
|
|
123
123
|
|
124
124
|
def test_spawn_closing_multiple_fds_with_array_keys
|
125
125
|
rd, wr = IO.pipe
|
126
|
-
pid = _spawn("exec 2>/dev/null 101>&#{wr.
|
126
|
+
pid = _spawn("exec 2>/dev/null 101>&#{wr.posix_fileno} || exit 1", [rd, wr, :out] => :close)
|
127
127
|
assert_process_exit_status pid, 1
|
128
128
|
ensure
|
129
129
|
[rd, wr].each { |fd| fd.close rescue nil }
|
@@ -145,7 +145,7 @@ module SpawnImplementationTests
|
|
145
145
|
|
146
146
|
def test_spawn_redirect_fds_with_fd_numbers
|
147
147
|
rd, wr = IO.pipe
|
148
|
-
pid = _spawn("echo", "hello world", 1 => wr.
|
148
|
+
pid = _spawn("echo", "hello world", 1 => wr.posix_fileno, rd.posix_fileno => :close)
|
149
149
|
wr.close
|
150
150
|
output = rd.read
|
151
151
|
assert_process_exit_ok pid
|
@@ -181,7 +181,7 @@ module SpawnImplementationTests
|
|
181
181
|
# have to pass it explicitly as fd => fd.
|
182
182
|
def test_explicitly_passing_an_fd_as_open
|
183
183
|
rd, wr = IO.pipe
|
184
|
-
pid = _spawn("exec 101>&#{wr.
|
184
|
+
pid = _spawn("exec 101>&#{wr.posix_fileno} || exit 1", wr => wr)
|
185
185
|
assert_process_exit_ok pid
|
186
186
|
ensure
|
187
187
|
[rd, wr].each { |fd| fd.close rescue nil }
|
data/test/test_system.rb
CHANGED
@@ -6,24 +6,24 @@ class SystemTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def test_system
|
8
8
|
ret = system("true")
|
9
|
-
assert_equal
|
10
|
-
assert_equal $?.exitstatus
|
9
|
+
assert_equal true, ret
|
10
|
+
assert_equal 0, $?.exitstatus
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_system_nonzero
|
14
14
|
ret = system("false")
|
15
|
-
assert_equal
|
16
|
-
assert_equal $?.exitstatus
|
15
|
+
assert_equal false, ret
|
16
|
+
assert_equal 1, $?.exitstatus
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_system_nonzero_via_sh
|
20
20
|
ret = system("exit 1")
|
21
|
-
assert_equal
|
22
|
-
assert_equal $?.exitstatus
|
21
|
+
assert_equal false, ret
|
22
|
+
assert_equal 1, $?.exitstatus
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_system_failure
|
26
26
|
ret = system("nosuch")
|
27
|
-
assert_equal
|
27
|
+
assert_equal false, ret
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posix-spawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 6
|
10
|
+
version: 0.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Tomayko
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-04-19 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
requirements: []
|
98
98
|
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.4.2
|
101
101
|
signing_key:
|
102
102
|
specification_version: 3
|
103
103
|
summary: posix_spawnp(2) for ruby
|