right_popen 1.0.18 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
@@ -28,13 +28,13 @@ module RightScale
|
|
28
28
|
class Process
|
29
29
|
attr_reader :pid, :stdin, :stdout, :stderr, :status_fd
|
30
30
|
attr_accessor :status
|
31
|
-
|
31
|
+
|
32
32
|
def initialize(parameters={})
|
33
33
|
parameters[:locale] = true unless parameters.has_key?(:locale)
|
34
34
|
@parameters = parameters
|
35
35
|
@status_fd = nil
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def fork(cmd)
|
39
39
|
@cmd = cmd
|
40
40
|
stdin_r, stdin_w = IO.pipe
|
@@ -58,7 +58,13 @@ module RightScale
|
|
58
58
|
|
59
59
|
status_r.close
|
60
60
|
status_w.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
61
|
-
|
61
|
+
|
62
|
+
ObjectSpace.each_object(IO) do |io|
|
63
|
+
if ![STDIN, STDOUT, STDERR, status_w].include?(io)
|
64
|
+
io.close unless io.closed?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
62
68
|
if group = get_group
|
63
69
|
::Process.egid = group
|
64
70
|
::Process.gid = group
|
@@ -72,7 +78,7 @@ module RightScale
|
|
72
78
|
Dir.chdir(@parameters[:directory]) if @parameters[:directory]
|
73
79
|
|
74
80
|
ENV["LC_ALL"] = "C" if @parameters[:locale]
|
75
|
-
|
81
|
+
|
76
82
|
@parameters[:environment].each do |key,value|
|
77
83
|
ENV[key.to_s] = value.to_s
|
78
84
|
end if @parameters[:environment]
|
data/lib/right_popen/version.rb
CHANGED
@@ -96,6 +96,7 @@ module RightScale::RightPopen
|
|
96
96
|
flexmock(::IO).should_receive(:select).with([@input], [@output], nil, 0.1).once.and_return([[], [@output], []])
|
97
97
|
@write.should_receive(:call).with().once.and_return(value)
|
98
98
|
value.should_receive(:[]).with(30..-1).and_return("")
|
99
|
+
value.should_receive("empty?").and_return(false)
|
99
100
|
@output.should_receive(:write_nonblock).with(value).once.and_return(30)
|
100
101
|
flexmock(::Process).should_receive(:waitpid2).with(42, ::Process::WNOHANG).once.and_return(nil)
|
101
102
|
a.tick.should be_false
|
@@ -109,6 +110,8 @@ module RightScale::RightPopen
|
|
109
110
|
@write.should_receive(:call).with().once.and_return(value)
|
110
111
|
value.should_receive(:[]).with(30..-1).and_return(other)
|
111
112
|
other.should_receive(:[]).with(20..-1).and_return("")
|
113
|
+
value.should_receive("empty?").and_return(false)
|
114
|
+
other.should_receive("empty?").and_return(false)
|
112
115
|
@output.should_receive(:write_nonblock).with(value).once.and_return(30)
|
113
116
|
@output.should_receive(:write_nonblock).with(other).once.and_return(20)
|
114
117
|
flexmock(::Process).should_receive(:waitpid2).with(42, ::Process::WNOHANG).and_return(nil)
|
@@ -33,7 +33,7 @@ module RightScale::RightPopen
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should handle utilities that expect input' do
|
36
|
-
out, err = Utilities::run("echo foo; read; echo bar >&2")
|
36
|
+
out, err = Utilities::run("echo foo; read unused_input; echo bar >&2")
|
37
37
|
out.should == "foo\n"
|
38
38
|
err.should == "bar\n"
|
39
39
|
end
|
data/spec/right_popen_spec.rb
CHANGED
@@ -58,6 +58,21 @@ module RightScale
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
it 'should close all IO handlers, except STDIN, STDOUT and STDERR' do
|
62
|
+
GC.start
|
63
|
+
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_status.rb'))}\" #{EXIT_STATUS}"
|
64
|
+
runner = Runner.new
|
65
|
+
status = runner.run_right_popen(command)
|
66
|
+
status.status.exitstatus.should == EXIT_STATUS
|
67
|
+
useless_handlers = 0
|
68
|
+
ObjectSpace.each_object(IO) do |io|
|
69
|
+
if ![STDIN, STDOUT, STDERR].include?(io)
|
70
|
+
useless_handlers += 1 unless io.closed?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
useless_handlers.should == 0
|
74
|
+
end
|
75
|
+
|
61
76
|
it 'should preserve the integrity of stdout when stderr is unavailable' do
|
62
77
|
count = LARGE_OUTPUT_COUNTER
|
63
78
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_stdout_only.rb'))}\" #{count}"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_popen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 19
|
10
|
+
version: 1.0.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Messier
|
@@ -17,12 +17,10 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date:
|
20
|
+
date: 2012-02-29 00:00:00 -08:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
name: eventmachine
|
25
|
-
prerelease: false
|
26
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
25
|
none: false
|
28
26
|
requirements:
|
@@ -34,11 +32,11 @@ dependencies:
|
|
34
32
|
- 12
|
35
33
|
- 11
|
36
34
|
version: 0.12.11
|
35
|
+
name: eventmachine
|
36
|
+
prerelease: false
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
|
-
prerelease: false
|
42
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
43
41
|
none: false
|
44
42
|
requirements:
|
@@ -49,11 +47,11 @@ dependencies:
|
|
49
47
|
- 1
|
50
48
|
- 3
|
51
49
|
version: "1.3"
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
52
|
type: :development
|
53
53
|
version_requirements: *id002
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
|
-
name: rake
|
56
|
-
prerelease: false
|
57
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
56
|
none: false
|
59
57
|
requirements:
|
@@ -65,11 +63,11 @@ dependencies:
|
|
65
63
|
- 8
|
66
64
|
- 7
|
67
65
|
version: 0.8.7
|
66
|
+
name: rake
|
67
|
+
prerelease: false
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id003
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name: flexmock
|
72
|
-
prerelease: false
|
73
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
74
72
|
none: false
|
75
73
|
requirements:
|
@@ -79,6 +77,8 @@ dependencies:
|
|
79
77
|
segments:
|
80
78
|
- 0
|
81
79
|
version: "0"
|
80
|
+
name: flexmock
|
81
|
+
prerelease: false
|
82
82
|
type: :development
|
83
83
|
version_requirements: *id004
|
84
84
|
description: |
|