exec_sandbox 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09f406c9093bf2a8b3fb29e4eff7fb66440212e4
4
- data.tar.gz: d1843fe96b2b322628773e4c492aa30876939bb9
3
+ metadata.gz: a9eb9c9752284a147c878f5271f7eb99d32290cc
4
+ data.tar.gz: 3e3c90d77b8bec213065c8b5a512a5ab99de8e88
5
5
  SHA512:
6
- metadata.gz: 72dc4cb65baf9b34dd5329ed9d454e7d9ebc38926337122e5ecba16e851fad4100542130f8e91b032f2543278cd96b5247ca67775a1c551bfab63412eb047bed
7
- data.tar.gz: 75139dd187ab0dcb646d1257a4101806480ce6b26911beb1084758e89acebeaae505f8bc9723a7f7372fcf28d608f9764a8f36e8c4bce93021fbc6b5770b08d9
6
+ metadata.gz: be2d2e056472f27f2f7b8a3add5360e9ae8270a0fc86c1ec02d75080cf61d52f255fd05b7ff5a829b95451598eb090a3f967ce23b082c14d28674478ced13427
7
+ data.tar.gz: f084d894ad94a4c2d2e1112a5a11e03e6963a85da8a9318510d581c6162ff61acc8d67deaf348510a136ec8bca21a352fb292906d917c7f9778c5fa8d4a3a903
data/Gemfile CHANGED
@@ -1,14 +1,14 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Add dependencies required to use your gem here.
4
- gem 'ffi', '>= 1.9.3'
4
+ gem 'ffi', '>= 1.9.6'
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
9
  gem 'rdoc', '>= 3.10'
10
- gem 'rspec', '>= 2.14.1'
11
- gem 'yard', '>= 0.8.7.3'
10
+ gem 'rspec', '>= 3.1.0'
11
+ gem 'yard', '>= 0.8.7.6'
12
12
  gem 'yard-rspec', '>= 0.1'
13
13
  gem 'bundler', '>= 1.3.5'
14
14
  gem 'jeweler', '>= 2.0.1'
@@ -1,25 +1,26 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
4
+ addressable (2.3.6)
5
5
  builder (3.2.2)
6
- descendants_tracker (0.0.3)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
7
8
  diff-lcs (1.2.5)
8
- docile (1.1.3)
9
+ docile (1.1.5)
9
10
  faraday (0.9.0)
10
11
  multipart-post (>= 1.2, < 3)
11
- ffi (1.9.3)
12
- git (1.2.6)
13
- github_api (0.11.2)
12
+ ffi (1.9.6)
13
+ git (1.2.8)
14
+ github_api (0.12.2)
14
15
  addressable (~> 2.3)
15
- descendants_tracker (~> 0.0.1)
16
+ descendants_tracker (~> 0.0.4)
16
17
  faraday (~> 0.8, < 0.10)
17
- hashie (>= 1.2)
18
+ hashie (>= 3.3)
18
19
  multi_json (>= 1.7.5, < 2.0)
19
- nokogiri (~> 1.6.0)
20
+ nokogiri (~> 1.6.3)
20
21
  oauth2
21
- hashie (2.0.5)
22
- highline (1.6.20)
22
+ hashie (3.3.1)
23
+ highline (1.6.21)
23
24
  jeweler (2.0.1)
24
25
  builder
25
26
  bundler (>= 1.0)
@@ -30,38 +31,42 @@ GEM
30
31
  rake
31
32
  rdoc
32
33
  json (1.8.1)
33
- jwt (0.1.11)
34
- multi_json (>= 1.5)
35
- mini_portile (0.5.2)
36
- multi_json (1.8.4)
34
+ jwt (1.0.0)
35
+ mini_portile (0.6.1)
36
+ multi_json (1.10.1)
37
37
  multi_xml (0.5.5)
38
38
  multipart-post (2.0.0)
39
- nokogiri (1.6.1)
40
- mini_portile (~> 0.5.0)
41
- oauth2 (0.9.3)
39
+ nokogiri (1.6.4.1)
40
+ mini_portile (~> 0.6.0)
41
+ oauth2 (1.0.0)
42
42
  faraday (>= 0.8, < 0.10)
43
- jwt (~> 0.1.8)
43
+ jwt (~> 1.0)
44
44
  multi_json (~> 1.3)
45
45
  multi_xml (~> 0.5)
46
46
  rack (~> 1.2)
47
47
  rack (1.5.2)
48
- rake (10.1.1)
49
- rdoc (4.1.1)
48
+ rake (10.3.2)
49
+ rdoc (4.1.2)
50
50
  json (~> 1.4)
51
- rspec (2.14.1)
52
- rspec-core (~> 2.14.0)
53
- rspec-expectations (~> 2.14.0)
54
- rspec-mocks (~> 2.14.0)
55
- rspec-core (2.14.7)
56
- rspec-expectations (2.14.5)
57
- diff-lcs (>= 1.1.3, < 2.0)
58
- rspec-mocks (2.14.5)
59
- simplecov (0.8.2)
51
+ rspec (3.1.0)
52
+ rspec-core (~> 3.1.0)
53
+ rspec-expectations (~> 3.1.0)
54
+ rspec-mocks (~> 3.1.0)
55
+ rspec-core (3.1.7)
56
+ rspec-support (~> 3.1.0)
57
+ rspec-expectations (3.1.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.1.0)
60
+ rspec-mocks (3.1.3)
61
+ rspec-support (~> 3.1.0)
62
+ rspec-support (3.1.2)
63
+ simplecov (0.9.1)
60
64
  docile (~> 1.1.0)
61
- multi_json
65
+ multi_json (~> 1.0)
62
66
  simplecov-html (~> 0.8.0)
63
67
  simplecov-html (0.8.0)
64
- yard (0.8.7.3)
68
+ thread_safe (0.3.4)
69
+ yard (0.8.7.6)
65
70
  yard-rspec (0.1)
66
71
  yard
67
72
 
@@ -70,10 +75,10 @@ PLATFORMS
70
75
 
71
76
  DEPENDENCIES
72
77
  bundler (>= 1.3.5)
73
- ffi (>= 1.9.3)
78
+ ffi (>= 1.9.6)
74
79
  jeweler (>= 2.0.1)
75
80
  rdoc (>= 3.10)
76
- rspec (>= 2.14.1)
81
+ rspec (>= 3.1.0)
77
82
  simplecov
78
- yard (>= 0.8.7.3)
83
+ yard (>= 0.8.7.6)
79
84
  yard-rspec (>= 0.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.3.0
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: exec_sandbox 0.3.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "exec_sandbox"
8
- s.version = "0.2.6"
9
+ s.version = "0.3.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Victor Costan"]
12
- s.date = "2014-02-06"
14
+ s.date = "2014-11-19"
13
15
  s.description = "Temporary users and groups, rlimits"
14
16
  s.email = "costan@gmail.com"
15
17
  s.extra_rdoc_files = [
@@ -49,37 +51,36 @@ Gem::Specification.new do |s|
49
51
  ]
50
52
  s.homepage = "http://github.com/pwnall/exec_sandbox"
51
53
  s.licenses = ["MIT"]
52
- s.require_paths = ["lib"]
53
- s.rubygems_version = "2.0.14"
54
+ s.rubygems_version = "2.4.4"
54
55
  s.summary = "Run foreign binaries using POSIX sandboxing features"
55
56
 
56
57
  if s.respond_to? :specification_version then
57
58
  s.specification_version = 4
58
59
 
59
60
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
- s.add_runtime_dependency(%q<ffi>, [">= 1.9.3"])
61
+ s.add_runtime_dependency(%q<ffi>, [">= 1.9.6"])
61
62
  s.add_development_dependency(%q<rdoc>, [">= 3.10"])
62
- s.add_development_dependency(%q<rspec>, [">= 2.14.1"])
63
- s.add_development_dependency(%q<yard>, [">= 0.8.7.3"])
63
+ s.add_development_dependency(%q<rspec>, [">= 3.1.0"])
64
+ s.add_development_dependency(%q<yard>, [">= 0.8.7.6"])
64
65
  s.add_development_dependency(%q<yard-rspec>, [">= 0.1"])
65
66
  s.add_development_dependency(%q<bundler>, [">= 1.3.5"])
66
67
  s.add_development_dependency(%q<jeweler>, [">= 2.0.1"])
67
68
  s.add_development_dependency(%q<simplecov>, [">= 0"])
68
69
  else
69
- s.add_dependency(%q<ffi>, [">= 1.9.3"])
70
+ s.add_dependency(%q<ffi>, [">= 1.9.6"])
70
71
  s.add_dependency(%q<rdoc>, [">= 3.10"])
71
- s.add_dependency(%q<rspec>, [">= 2.14.1"])
72
- s.add_dependency(%q<yard>, [">= 0.8.7.3"])
72
+ s.add_dependency(%q<rspec>, [">= 3.1.0"])
73
+ s.add_dependency(%q<yard>, [">= 0.8.7.6"])
73
74
  s.add_dependency(%q<yard-rspec>, [">= 0.1"])
74
75
  s.add_dependency(%q<bundler>, [">= 1.3.5"])
75
76
  s.add_dependency(%q<jeweler>, [">= 2.0.1"])
76
77
  s.add_dependency(%q<simplecov>, [">= 0"])
77
78
  end
78
79
  else
79
- s.add_dependency(%q<ffi>, [">= 1.9.3"])
80
+ s.add_dependency(%q<ffi>, [">= 1.9.6"])
80
81
  s.add_dependency(%q<rdoc>, [">= 3.10"])
81
- s.add_dependency(%q<rspec>, [">= 2.14.1"])
82
- s.add_dependency(%q<yard>, [">= 0.8.7.3"])
82
+ s.add_dependency(%q<rspec>, [">= 3.1.0"])
83
+ s.add_dependency(%q<yard>, [">= 0.8.7.6"])
83
84
  s.add_dependency(%q<yard-rspec>, [">= 0.1"])
84
85
  s.add_dependency(%q<bundler>, [">= 1.3.5"])
85
86
  s.add_dependency(%q<jeweler>, [">= 2.0.1"])
@@ -9,21 +9,41 @@ module Wait4
9
9
  # this process
10
10
  # @return [Hash] exit code and resource usage information
11
11
  def self.wait4(pid)
12
- status_ptr = FFI::MemoryPointer.new :int
13
- rusage = ExecSandbox::Wait4::Rusage.new
14
- returned_pid = LibC.wait4(pid, status_ptr, 0, rusage.pointer)
15
- raise SystemCallError, FFI.errno if returned_pid < 0
16
- status = { bits: status_ptr.read_int }
17
- status_ptr.free
12
+ _wait4 pid, 0
13
+ end
18
14
 
19
- signal_code = status[:bits] & 0x7f
20
- status[:exit_code] = (signal_code != 0) ? -signal_code : status[:bits] >> 8
21
- status[:user_time] = rusage[:ru_utime_sec] +
22
- rusage[:ru_utime_usec] * 0.000_001
23
- status[:system_time] = rusage[:ru_stime_sec] +
24
- rusage[:ru_stime_usec] * 0.000_001
25
- status[:rss] = rusage[:ru_maxrss] / 1024.0
26
- return status
15
+ # Collects a child process' exit status and resource usage.
16
+ #
17
+ # @param [Fixnum] pid the PID of the process to wait for; should be a child of
18
+ # this process
19
+ # @return [Hash] exit code and resource usage information; nil if the process
20
+ # hasn't terminated
21
+ def self.wait4_nonblock(pid)
22
+ _wait4 pid, WNOHANG
23
+ end
24
+
25
+ class <<self
26
+ # @private
27
+ def _wait4(pid, options)
28
+ status_ptr = FFI::MemoryPointer.new :int
29
+ rusage = ExecSandbox::Wait4::Rusage.new
30
+ returned_pid = LibC.wait4(pid, status_ptr, options, rusage.pointer)
31
+ raise SystemCallError, FFI.errno if returned_pid < 0
32
+ return nil if returned_pid == 0
33
+
34
+ status = { bits: status_ptr.read_int }
35
+ status_ptr.free
36
+
37
+ signal_code = status[:bits] & 0x7f
38
+ status[:exit_code] = (signal_code != 0) ? -signal_code : status[:bits] >> 8
39
+ status[:user_time] = rusage[:ru_utime_sec] +
40
+ rusage[:ru_utime_usec] * 0.000_001
41
+ status[:system_time] = rusage[:ru_stime_sec] +
42
+ rusage[:ru_stime_usec] * 0.000_001
43
+ status[:rss] = rusage[:ru_maxrss] / 1024.0
44
+ return status
45
+ end
46
+ private :_wait4
27
47
  end
28
48
 
29
49
  # Maps wait4 in libc.
@@ -34,6 +54,9 @@ module Wait4
34
54
  blocking: true
35
55
  end # module ExecSandbox::Wait4::Libc
36
56
 
57
+ # Option passed to LibC::wait4.
58
+ WNOHANG = 1
59
+
37
60
  # Maps struct rusage in sys/resource.h, used by wait4.
38
61
  class Rusage < FFI::Struct
39
62
  # Total amount of user time used.
@@ -7,30 +7,30 @@ describe ExecSandbox::Wait4 do
7
7
  pid = Kernel.fork { Process.exec bin_fixture(:exit_arg), '42' }
8
8
  @status = ExecSandbox::Wait4.wait4 pid
9
9
  end
10
-
10
+
11
11
  it 'should have the correct exit status' do
12
12
  @status[:exit_code].should == 42
13
13
  end
14
-
14
+
15
15
  it 'should not take more than 1s of user time' do
16
16
  @status[:user_time].should < 1
17
17
  end
18
-
18
+
19
19
  it 'should not take more than 1s of system time' do
20
20
  @status[:system_time].should < 1
21
21
  end
22
22
  end
23
-
23
+
24
24
  describe 'churn.rb' do
25
25
  before do
26
26
  pid = Kernel.fork { Process.exec bin_fixture(:churn), '', '2' }
27
27
  @status = ExecSandbox::Wait4.wait4 pid
28
28
  end
29
-
29
+
30
30
  it 'should have the correct exit status' do
31
31
  @status[:exit_code].should == 0
32
32
  end
33
-
33
+
34
34
  it 'should not take more than 3s of user time' do
35
35
  @status[:user_time].should < 3
36
36
  end
@@ -38,10 +38,44 @@ describe ExecSandbox::Wait4 do
38
38
  it 'should not take less than 1s of user time' do
39
39
  @status[:user_time].should > 1
40
40
  end
41
-
41
+
42
42
  it 'should not take more than 1s of system time' do
43
43
  @status[:system_time].should < 1
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ describe '#wait4_nonblock' do
49
+ describe 'churn.rb' do
50
+ before do
51
+ @pid = Kernel.fork { Process.exec bin_fixture(:churn), '', '1' }
52
+ end
53
+
54
+ after do
55
+ begin
56
+ ExecSandbox::Wait4.wait4 @pid
57
+ rescue Errno::ECHILD
58
+ # The child's status has already been reaped.
59
+ end
60
+ end
61
+
62
+ it 'returns nil when wait4 would block' do
63
+ ExecSandbox::Wait4.wait4_nonblock(@pid).should == nil
64
+ end
65
+
66
+ it 'does not block' do
67
+ t_start = Time.now
68
+ ExecSandbox::Wait4.wait4_nonblock @pid
69
+ t_end = Time.now
70
+ (t_end - t_start).should < 0.1
71
+ end
72
+
73
+ it 'returns resource usage data if called after the process ends' do
74
+ sleep 2
75
+ status = ExecSandbox::Wait4.wait4_nonblock @pid
76
+ status[:user_time].should > 0.5
77
+ status[:user_time].should < 2
78
+ end
79
+ end
80
+ end
47
81
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exec_sandbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-06 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.3
19
+ version: 1.9.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.9.3
26
+ version: 1.9.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.1
47
+ version: 3.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.1
54
+ version: 3.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.7.3
61
+ version: 0.8.7.6
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.7.3
68
+ version: 0.8.7.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.3.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.3.5
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: jeweler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: 2.0.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.0.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: Temporary users and groups, rlimits
@@ -130,9 +130,9 @@ extra_rdoc_files:
130
130
  - LICENSE.txt
131
131
  - README.rdoc
132
132
  files:
133
- - .document
134
- - .project
135
- - .rspec
133
+ - ".document"
134
+ - ".project"
135
+ - ".rspec"
136
136
  - Gemfile
137
137
  - Gemfile.lock
138
138
  - LICENSE.txt
@@ -169,17 +169,17 @@ require_paths:
169
169
  - lib
170
170
  required_ruby_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '>='
177
+ - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
181
  rubyforge_project:
182
- rubygems_version: 2.0.14
182
+ rubygems_version: 2.4.4
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: Run foreign binaries using POSIX sandboxing features