posix-spawn 0.3.11 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +0 -6
- data/bin/posix-spawn-benchmark +16 -116
- data/ext/posix-spawn.c +28 -28
- data/lib/posix/spawn/child.rb +1 -2
- data/lib/posix/spawn/version.rb +1 -1
- data/lib/posix/spawn.rb +4 -4
- data/posix-spawn.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 586d0f0f9057e34308bf74b8012308d58554be84
|
4
|
+
data.tar.gz: fc46031fe4302b9c09bac390c758006e06d42a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c48ddad2fb6bd679db842a9ab7afb37b0c07963b143e8c3e9537a48216b0b61a7761c2f2214fdfd5f30072c9d0429717aa65cfc2e005e1797a7b2802486391
|
7
|
+
data.tar.gz: f18771b44bff3cf3ce268abb4969ab2a4750df248bcab1ed027fcb84e475b1172aaadfb7051451dda475391cfeabfe8100fd4b1dc818ba82d7e20f9bfcd82188
|
data/COPYING
CHANGED
@@ -20,9 +20,3 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
20
20
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
21
21
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
22
|
SOFTWARE.
|
23
|
-
|
24
|
-
A small portion of the environ dup'ing code in ext/posix-spawn.c
|
25
|
-
was taken from glibc <http://www.gnu.org/s/libc/> and is maybe
|
26
|
-
Copyright (c) 2011 by The Free Software Foundation or maybe
|
27
|
-
by others mentioned in the glibc LICENSES file. glibc is
|
28
|
-
distributed under the terms of the LGPL license.
|
data/bin/posix-spawn-benchmark
CHANGED
@@ -1,117 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
graphmode = false
|
19
|
-
ARGV.options do |o|
|
20
|
-
o.set_summary_indent(' ')
|
21
|
-
o.on("-n", "--count=num") { |val| iterations = val.to_i }
|
22
|
-
o.on("-m", "--mem-size=MB") { |val| allocate = val.to_i * (1024 ** 2) }
|
23
|
-
o.on("-g", "--graph") { graphmode = true }
|
24
|
-
o.on_tail("-h", "--help") { exec "grep ^#/ <'#{__FILE__}' |cut -c4-" }
|
25
|
-
o.parse!
|
26
|
-
end
|
27
|
-
|
28
|
-
if graphmode
|
29
|
-
bloat = []
|
30
|
-
data = {}
|
31
|
-
chunk = allocate / 10
|
32
|
-
max = 0
|
33
|
-
|
34
|
-
10.times do
|
35
|
-
puts "allocating #{chunk / (1024 ** 2)}MB (#{(bloat.size+1) * chunk / (1024 ** 2)}MB total)"
|
36
|
-
bloat << ('x' * chunk)
|
37
|
-
# size = bloat.size / (1024 ** 2)
|
38
|
-
|
39
|
-
%w[ fspawn pspawn ].each do |type|
|
40
|
-
print " - benchmarking #{type}... "
|
41
|
-
time = Benchmark.realtime do
|
42
|
-
iterations.times do
|
43
|
-
pid = POSIX::Spawn.send(type, 'true')
|
44
|
-
Process.wait(pid)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
puts "done (#{time})"
|
48
|
-
|
49
|
-
data[type] ||= []
|
50
|
-
data[type] << time
|
51
|
-
max = time if time > max
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
max = max < 0.5 ? (max * 10).round / 10.0 : max.ceil
|
56
|
-
minmb, maxmb = chunk/(1024**2), allocate/(1024**2)
|
57
|
-
series = %w[ fspawn pspawn ].map{|name| data[name].map{|d| "%.2f" % d }.join(',') }
|
58
|
-
|
59
|
-
chart = {
|
60
|
-
:chs => '900x200',
|
61
|
-
:cht => 'bvg', # grouped vertical bar chart
|
62
|
-
:chtt => "posix-spawn-benchmark --graph --count #{iterations} --mem-size #{maxmb} (#{RUBY_PLATFORM})",
|
63
|
-
|
64
|
-
:chf => 'bg,s,f8f8f8', # background
|
65
|
-
:chbh => 'a,5,25', # 25px between bar groups
|
66
|
-
|
67
|
-
:chd => "t:#{series.join('|')}", # data
|
68
|
-
:chds => "0,#{max}", # scale
|
69
|
-
:chdl => 'fspawn (fork+exec)|pspawn (posix_spawn)', # legend
|
70
|
-
:chco => '1f77b4,ff7f0e', # colors
|
71
|
-
|
72
|
-
:chxt => 'x,y',
|
73
|
-
:chxr => "1,0,#{max},#{max/5}", # y labels up to max time
|
74
|
-
:chxs => '1N** secs', # y labels are +=' secs'
|
75
|
-
:chxl => "0:|#{minmb.step(maxmb, maxmb/10).map{ |mb| "#{mb} MB"}.join('|')}", # x bucket labels
|
76
|
-
}
|
77
|
-
|
78
|
-
url = "https://chart.googleapis.com/chart?"
|
79
|
-
url += chart.map do |key, val|
|
80
|
-
"#{key}=#{val.gsub(' ','%20').gsub('(','%28').gsub(')','%29').gsub('+','%2B')}"
|
81
|
-
end.join('&')
|
82
|
-
url += '#.png'
|
83
|
-
|
84
|
-
puts url
|
85
|
-
|
86
|
-
exit!
|
87
|
-
end
|
88
|
-
|
89
|
-
puts "benchmarking fork/exec vs. posix_spawn over #{iterations} runs" +
|
90
|
-
" at #{allocate / (1024 ** 2)}M res"
|
91
|
-
|
92
|
-
# bloat the process
|
93
|
-
bloat = 'x' * allocate
|
94
|
-
|
95
|
-
# run the benchmarks
|
96
|
-
bm 40 do |x|
|
97
|
-
x.report("fspawn (fork/exec):") do
|
98
|
-
iterations.times do
|
99
|
-
pid = POSIX::Spawn.fspawn('true')
|
100
|
-
Process.wait(pid)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
x.report("pspawn (posix_spawn):") do
|
104
|
-
iterations.times do
|
105
|
-
pid = POSIX::Spawn.pspawn('true')
|
106
|
-
Process.wait(pid)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
if Process.respond_to?(:spawn)
|
110
|
-
x.report("spawn (native):") do
|
111
|
-
iterations.times do
|
112
|
-
pid = Process.spawn('true')
|
113
|
-
Process.wait(pid)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'posix-spawn-benchmark' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("posix-spawn", "posix-spawn-benchmark")
|
data/ext/posix-spawn.c
CHANGED
@@ -45,7 +45,7 @@ static VALUE rb_mPOSIXSpawn;
|
|
45
45
|
* an actual fd number:
|
46
46
|
* - The symbols :in, :out, or :err for fds 0, 1, or 2.
|
47
47
|
* - An IO object. (IO#fileno is returned)
|
48
|
-
* -
|
48
|
+
* - An Integer.
|
49
49
|
*
|
50
50
|
* Returns the fd number >= 0 if one could be established, or -1 if the object
|
51
51
|
* does not map to an fd.
|
@@ -56,8 +56,12 @@ posixspawn_obj_to_fd(VALUE obj)
|
|
56
56
|
int fd = -1;
|
57
57
|
switch (TYPE(obj)) {
|
58
58
|
case T_FIXNUM:
|
59
|
-
|
60
|
-
fd
|
59
|
+
case T_BIGNUM:
|
60
|
+
/* Integer fd number
|
61
|
+
* rb_fix2int takes care of raising if the provided object is a
|
62
|
+
* Bignum and is out of range of an int
|
63
|
+
*/
|
64
|
+
fd = (int)rb_fix2int(obj);
|
61
65
|
break;
|
62
66
|
|
63
67
|
case T_SYMBOL:
|
@@ -94,7 +98,7 @@ posixspawn_obj_to_fd(VALUE obj)
|
|
94
98
|
/*
|
95
99
|
* Hash iterator that sets up the posix_spawn_file_actions_t with addclose
|
96
100
|
* operations. Only hash pairs whose value is :close are processed. Keys may
|
97
|
-
* be the :in, :out, :err, an IO object, or
|
101
|
+
* be the :in, :out, :err, an IO object, or an Integer fd number.
|
98
102
|
*
|
99
103
|
* Returns ST_DELETE when an addclose operation was added; ST_CONTINUE when
|
100
104
|
* no operation was performed.
|
@@ -269,27 +273,22 @@ each_env_check_i(VALUE key, VALUE val, VALUE arg)
|
|
269
273
|
static int
|
270
274
|
each_env_i(VALUE key, VALUE val, VALUE arg)
|
271
275
|
{
|
272
|
-
char *name = StringValuePtr(key);
|
273
|
-
size_t
|
276
|
+
const char *name = StringValuePtr(key);
|
277
|
+
const size_t name_len = strlen(name);
|
274
278
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
if (!
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
do
|
287
|
-
dp[0] = dp[1];
|
288
|
-
while (*dp++);
|
289
|
-
/* Continue the loop in case NAME appears again. */
|
279
|
+
char **envp = (char **)arg;
|
280
|
+
size_t i, j;
|
281
|
+
|
282
|
+
for (i = 0; envp[i];) {
|
283
|
+
const char *ev = envp[i];
|
284
|
+
|
285
|
+
if (strlen(ev) > name_len && !memcmp(ev, name, name_len) && ev[name_len] == '=') {
|
286
|
+
for (j = i; envp[j]; ++j)
|
287
|
+
envp[j] = envp[j + 1];
|
288
|
+
continue;
|
290
289
|
}
|
291
|
-
|
292
|
-
|
290
|
+
i++;
|
291
|
+
}
|
293
292
|
|
294
293
|
/*
|
295
294
|
* Insert the new value if we have one. We can assume there is space
|
@@ -301,15 +300,15 @@ each_env_i(VALUE key, VALUE val, VALUE arg)
|
|
301
300
|
char *cval = StringValuePtr(val);
|
302
301
|
|
303
302
|
size_t cval_len = strlen(cval);
|
304
|
-
size_t ep_len =
|
303
|
+
size_t ep_len = name_len + 1 + cval_len + 1; /* +2 for null terminator and '=' separator */
|
305
304
|
|
306
305
|
/* find the last entry */
|
307
306
|
while (*ep != NULL) ++ep;
|
308
307
|
*ep = malloc(ep_len);
|
309
308
|
|
310
|
-
strncpy(*ep, name,
|
311
|
-
(*ep)[
|
312
|
-
strncpy(*ep +
|
309
|
+
strncpy(*ep, name, name_len);
|
310
|
+
(*ep)[name_len] = '=';
|
311
|
+
strncpy(*ep + name_len + 1, cval, cval_len);
|
313
312
|
(*ep)[ep_len-1] = 0;
|
314
313
|
}
|
315
314
|
|
@@ -373,6 +372,7 @@ rb_posixspawn_pspawn(VALUE self, VALUE env, VALUE argv, VALUE options)
|
|
373
372
|
|
374
373
|
if (RHASH_SIZE(env) > 0) {
|
375
374
|
int size = 0;
|
375
|
+
char **new_env;
|
376
376
|
|
377
377
|
char **curr = environ;
|
378
378
|
if (curr) {
|
@@ -387,7 +387,7 @@ rb_posixspawn_pspawn(VALUE self, VALUE env, VALUE argv, VALUE options)
|
|
387
387
|
size = 0;
|
388
388
|
}
|
389
389
|
|
390
|
-
|
390
|
+
new_env = calloc(size+RHASH_SIZE(env)+1, sizeof(char*));
|
391
391
|
for (i = 0; i < size; i++) {
|
392
392
|
new_env[i] = strdup(environ[i]);
|
393
393
|
}
|
data/lib/posix/spawn/child.rb
CHANGED
@@ -158,7 +158,7 @@ module POSIX
|
|
158
158
|
|
159
159
|
# grab exit status
|
160
160
|
@status = waitpid(pid)
|
161
|
-
rescue Object
|
161
|
+
rescue Object
|
162
162
|
[stdin, stdout, stderr].each { |fd| fd.close rescue nil }
|
163
163
|
if @status.nil?
|
164
164
|
if !@pgroup_kill
|
@@ -197,7 +197,6 @@ module POSIX
|
|
197
197
|
def read_and_write(input, stdin, stdout, stderr, timeout=nil, max=nil)
|
198
198
|
max = nil if max && max <= 0
|
199
199
|
@out, @err = '', ''
|
200
|
-
offset = 0
|
201
200
|
|
202
201
|
# force all string and IO encodings to BINARY under 1.9 for now
|
203
202
|
if @out.respond_to?(:force_encoding) and stdin.respond_to?(:set_encoding)
|
data/lib/posix/spawn/version.rb
CHANGED
data/lib/posix/spawn.rb
CHANGED
@@ -85,7 +85,7 @@ module POSIX
|
|
85
85
|
#
|
86
86
|
# spawn(command, :chdir => "/var/tmp")
|
87
87
|
#
|
88
|
-
# The :in, :out, :err,
|
88
|
+
# The :in, :out, :err, an Integer, an IO object or an Array option specify
|
89
89
|
# fd redirection. For example, stderr can be merged into stdout as follows:
|
90
90
|
#
|
91
91
|
# spawn(command, :err => :out)
|
@@ -460,11 +460,11 @@ module POSIX
|
|
460
460
|
|
461
461
|
# Determine whether object is fd-like.
|
462
462
|
#
|
463
|
-
# Returns true if object is an instance of IO,
|
463
|
+
# Returns true if object is an instance of IO, Integer >= 0, or one of the
|
464
464
|
# the symbolic names :in, :out, or :err.
|
465
465
|
def fd?(object)
|
466
466
|
case object
|
467
|
-
when
|
467
|
+
when Integer
|
468
468
|
object >= 0
|
469
469
|
when :in, :out, :err, STDIN, STDOUT, STDERR, $stdin, $stdout, $stderr, IO
|
470
470
|
true
|
@@ -486,7 +486,7 @@ module POSIX
|
|
486
486
|
STDOUT
|
487
487
|
when :err, 2
|
488
488
|
STDERR
|
489
|
-
when
|
489
|
+
when Integer
|
490
490
|
object >= 0 ? IO.for_fd(object) : nil
|
491
491
|
when IO
|
492
492
|
object
|
data/posix-spawn.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
|
12
12
|
s.authors = ['Ryan Tomayko', 'Aman Gupta']
|
13
13
|
s.email = ['r@tomayko.com', 'aman@tmm1.net']
|
14
|
-
s.licenses = ['MIT'
|
14
|
+
s.licenses = ['MIT']
|
15
15
|
|
16
16
|
s.add_development_dependency 'rake-compiler', '0.7.6'
|
17
17
|
s.add_development_dependency 'minitest', '>= 4'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posix-spawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
homepage: https://github.com/rtomayko/posix-spawn
|
76
76
|
licenses:
|
77
77
|
- MIT
|
78
|
-
- LGPL
|
79
78
|
metadata: {}
|
80
79
|
post_install_message:
|
81
80
|
rdoc_options: []
|
@@ -93,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
92
|
version: '0'
|
94
93
|
requirements: []
|
95
94
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.2
|
97
96
|
signing_key:
|
98
97
|
specification_version: 4
|
99
98
|
summary: posix_spawnp(2) for ruby
|