cheetah 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG +8 -0
- data/VERSION +1 -1
- data/lib/cheetah.rb +37 -19
- data/lib/cheetah/version.rb +2 -0
- metadata +7 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3e79228df3ba4822704c7f3e81fe0fdbec93a7a36f7935d2b117380470be1ed
|
4
|
+
data.tar.gz: f398f8b357f85c2c7cf8f08a790bb77f586e1d251eba4eea0d97ea940e651517
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06fbed837fee79bbf04be03355c8c339df1ffdf9d3f005743f6bcc7896a2c4a604a53f723e8cc2f95e6d07db4cd0b6ca105272ab0ac870b6d37d21baa15d4a38
|
7
|
+
data.tar.gz: 1ef2088f550bf7d7bf4c3ea7369fdef6ea3e9a49b36d5f5666f6ddcf449663e484073eb85a47f47f9e5d14b89ba6da13ac7b0065852884fb7fcc7f848f631d11
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.5.1 (2019-10-16)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Implement closing open fds after call to fork (bsc#1151960). This will work
|
5
|
+
only in linux system with mounted /proc. For other Unixes it works as before.
|
6
|
+
* drop support for ruby that is EOL (2.3 and lower)
|
7
|
+
* Added support for ruby 2.4, 2.5, 2.6
|
8
|
+
|
1
9
|
0.5.0 (2015-12-18)
|
2
10
|
------------------
|
3
11
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/cheetah.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "abstract_method"
|
2
4
|
require "logger"
|
3
5
|
require "shellwords"
|
@@ -142,16 +144,16 @@ module Cheetah
|
|
142
144
|
class DefaultRecorder < Recorder
|
143
145
|
# @private
|
144
146
|
STREAM_INFO = {
|
145
|
-
stdin:
|
147
|
+
stdin: { name: "Standard input", method: :info },
|
146
148
|
stdout: { name: "Standard output", method: :info },
|
147
149
|
stderr: { name: "Error output", method: :error }
|
148
|
-
}
|
150
|
+
}.freeze
|
149
151
|
|
150
152
|
def initialize(logger)
|
151
153
|
@logger = logger
|
152
154
|
|
153
155
|
@stream_used = { stdin: false, stdout: false, stderr: false }
|
154
|
-
@stream_buffer = { stdin: "",
|
156
|
+
@stream_buffer = { stdin: +"", stdout: +"", stderr: +"" }
|
155
157
|
end
|
156
158
|
|
157
159
|
def record_commands(commands)
|
@@ -212,13 +214,13 @@ module Cheetah
|
|
212
214
|
|
213
215
|
# @private
|
214
216
|
BUILTIN_DEFAULT_OPTIONS = {
|
215
|
-
stdin:
|
217
|
+
stdin: "",
|
216
218
|
stdout: nil,
|
217
219
|
stderr: nil,
|
218
220
|
logger: nil,
|
219
|
-
env:
|
221
|
+
env: {},
|
220
222
|
chroot: "/"
|
221
|
-
}
|
223
|
+
}.freeze
|
222
224
|
|
223
225
|
READ = 0 # @private
|
224
226
|
WRITE = 1 # @private
|
@@ -426,7 +428,7 @@ module Cheetah
|
|
426
428
|
# and nil is an IO-like object. We avoid detecting it directly to allow
|
427
429
|
# passing StringIO, mocks, etc.
|
428
430
|
{
|
429
|
-
stdin:
|
431
|
+
stdin: !options[:stdin].is_a?(String),
|
430
432
|
stdout: ![nil, :capture].include?(options[:stdout]),
|
431
433
|
stderr: ![nil, :capture].include?(options[:stderr])
|
432
434
|
}
|
@@ -434,9 +436,9 @@ module Cheetah
|
|
434
436
|
|
435
437
|
def build_streams(options, streamed)
|
436
438
|
{
|
437
|
-
stdin:
|
438
|
-
stdout: streamed[:stdout] ? options[:stdout] : StringIO.new(""),
|
439
|
-
stderr: streamed[:stderr] ? options[:stderr] : StringIO.new("")
|
439
|
+
stdin: streamed[:stdin] ? options[:stdin] : StringIO.new(options[:stdin]),
|
440
|
+
stdout: streamed[:stdout] ? options[:stdout] : StringIO.new(+""),
|
441
|
+
stderr: streamed[:stderr] ? options[:stderr] : StringIO.new(+"")
|
440
442
|
}
|
441
443
|
end
|
442
444
|
|
@@ -494,7 +496,7 @@ module Cheetah
|
|
494
496
|
return options if [nil, "/"].include?(options[:chroot])
|
495
497
|
|
496
498
|
options = options.dup
|
497
|
-
# delete chroot option otherwise in pipe will chroot each fork
|
499
|
+
# delete chroot option otherwise in pipe will chroot each fork recursively
|
498
500
|
root = options.delete(:chroot)
|
499
501
|
Dir.chroot(root)
|
500
502
|
# curdir can be outside chroot which is considered as security problem
|
@@ -520,8 +522,7 @@ module Cheetah
|
|
520
522
|
stdout: pipe_to_child,
|
521
523
|
stderr: pipes[:stderr]
|
522
524
|
},
|
523
|
-
options
|
524
|
-
)
|
525
|
+
options)
|
525
526
|
|
526
527
|
pipes[:stdin][READ].close
|
527
528
|
pipes[:stdin][WRITE].close
|
@@ -532,9 +533,7 @@ module Cheetah
|
|
532
533
|
into_pipe(STDOUT, pipes[:stdout])
|
533
534
|
into_pipe(STDERR, pipes[:stderr])
|
534
535
|
|
535
|
-
|
536
|
-
# don't know about any way how to detect the maximum file descriptor
|
537
|
-
# number portably in Ruby, I didn't implement it. Patches welcome.
|
536
|
+
close_fds
|
538
537
|
|
539
538
|
command, *args = commands.last
|
540
539
|
with_env(options[:env]) do
|
@@ -550,6 +549,27 @@ module Cheetah
|
|
550
549
|
end
|
551
550
|
end
|
552
551
|
|
552
|
+
# closes all open fds starting with 3 and above
|
553
|
+
def close_fds
|
554
|
+
# note: this will work only if unix has /proc filesystem. If it does not
|
555
|
+
# have it, it won't close other fds.
|
556
|
+
Dir.glob("/proc/self/fd/*").each do |path|
|
557
|
+
fd = File.basename(path).to_i
|
558
|
+
next if (0..2).include?(fd)
|
559
|
+
|
560
|
+
# here we intentionally ignore some failures when fd close failed
|
561
|
+
# rubocop:disable Lint/HandleExceptions
|
562
|
+
begin
|
563
|
+
IO.new(fd).close
|
564
|
+
# Ruby reserves some fds for its VM and it result in this exception
|
565
|
+
rescue ArgumentError
|
566
|
+
# Ignore if close failed with invalid FD
|
567
|
+
rescue Errno::EBADF
|
568
|
+
end
|
569
|
+
# rubocop:enable Lint/HandleExceptions
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
553
573
|
def fork_commands(commands, options)
|
554
574
|
pipes = { stdin: IO.pipe, stdout: IO.pipe, stderr: IO.pipe }
|
555
575
|
|
@@ -595,9 +615,7 @@ module Cheetah
|
|
595
615
|
ios_read, ios_write, ios_error = select(pipes_readable, pipes_writable,
|
596
616
|
pipes_readable + pipes_writable)
|
597
617
|
|
598
|
-
if !ios_error.empty?
|
599
|
-
raise IOError, "Error when communicating with executed program."
|
600
|
-
end
|
618
|
+
raise IOError, "Error when communicating with executed program." if !ios_error.empty?
|
601
619
|
|
602
620
|
ios_read.each do |pipe|
|
603
621
|
begin
|
data/lib/cheetah/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheetah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Majda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_method
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.9.11
|
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:
|
54
|
+
version: 0.9.11
|
55
55
|
description: Your swiss army knife for executing external commands in Ruby safely
|
56
56
|
and conveniently.
|
57
57
|
email: dmajda@suse.de
|
@@ -84,11 +84,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.4.5.1
|
87
|
+
rubygems_version: 3.0.3
|
89
88
|
signing_key:
|
90
89
|
specification_version: 4
|
91
90
|
summary: Your swiss army knife for executing external commands in Ruby safely and
|
92
91
|
conveniently.
|
93
92
|
test_files: []
|
94
|
-
has_rdoc:
|