binaryen 1.1.6.4 → 1.1.6.6
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 +4 -4
- data/lib/binaryen/command.rb +17 -15
- data/lib/binaryen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44bf5b373ce186bdee3006d16e8129bde2be3e952c1211d3ee550fb529cffbfe
|
4
|
+
data.tar.gz: c3ef7a60460cdc937e51b538ef4e6d94ebfba2167ff14821292881a9b91d6f1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290897e4df9079e57df51b4b684fa5ae496ea414c44d801ed8d2be5c167d5347812533511ee26b8f59520d645df1072df5c6368d218ab824d89b38e07373e7b5
|
7
|
+
data.tar.gz: c30ed5adcb899a8d938d211b3aa3e98e875ec061f19054efd5d7a803b9be0392f9215cbac61283147841e23171ead48391f06695aa06841a64a6be05d5ba57aa
|
data/lib/binaryen/command.rb
CHANGED
@@ -30,7 +30,7 @@ module Binaryen
|
|
30
30
|
def check!
|
31
31
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
32
32
|
if now >= @end_time
|
33
|
-
Process.kill("
|
33
|
+
Process.kill("TERM", @pid)
|
34
34
|
raise Timeout::Error, "Command timed out"
|
35
35
|
end
|
36
36
|
remaining_time = @end_time - now
|
@@ -50,43 +50,45 @@ module Binaryen
|
|
50
50
|
pid, iwr, ord, erd = popen4(*command)
|
51
51
|
timeout_checker = TimeoutChecker.new(end_time: end_time, pid: pid)
|
52
52
|
|
53
|
-
write_to_pipe(iwr, stdin, timeout_checker) if stdin
|
53
|
+
write_to_pipe(iwr, stdin, timeout_checker, pid) if stdin
|
54
|
+
|
54
55
|
if stderr
|
55
56
|
err_output = read_from_pipe(erd, timeout_checker)
|
56
|
-
write_to_pipe(stderr, err_output, timeout_checker, close_write: false)
|
57
|
+
write_to_pipe(stderr, err_output, timeout_checker, pid, close_write: false)
|
57
58
|
end
|
58
59
|
output = read_from_pipe(ord, timeout_checker)
|
59
|
-
wait_or_kill(pid, timeout_checker
|
60
|
+
wait_or_kill(pid, timeout_checker)
|
60
61
|
|
61
62
|
output
|
62
63
|
end
|
63
64
|
|
64
65
|
private
|
65
66
|
|
66
|
-
def write_to_pipe(pipe, stdin, timeout_checker, close_write: true)
|
67
|
+
def write_to_pipe(pipe, stdin, timeout_checker, pid, close_write: true)
|
67
68
|
offset = 0
|
68
69
|
length = stdin.bytesize
|
69
70
|
|
70
71
|
while offset < length
|
71
72
|
remaining_time = timeout_checker.check!
|
72
73
|
|
73
|
-
|
74
|
+
next unless IO.select(nil, [pipe], nil, remaining_time)
|
75
|
+
|
76
|
+
begin
|
74
77
|
written = pipe.write_nonblock(stdin.byteslice(offset, length), exception: false)
|
75
78
|
offset += written if written.is_a?(Integer)
|
76
|
-
|
77
|
-
|
79
|
+
rescue Errno::EPIPE
|
80
|
+
wait_or_kill(pid, timeout_checker, pid)
|
78
81
|
end
|
79
82
|
end
|
80
|
-
|
83
|
+
ensure
|
81
84
|
pipe.close_write if close_write
|
82
85
|
end
|
83
86
|
|
84
|
-
def read_from_pipe(pipe, timeout_checker)
|
87
|
+
def read_from_pipe(pipe, timeout_checker, close_read: true)
|
85
88
|
output = +""
|
86
89
|
|
87
90
|
while (result = pipe.read_nonblock(8192, exception: false))
|
88
91
|
remaining_time = timeout_checker.check!
|
89
|
-
raise Timeout::Error, "Command timed out" if remaining_time <= 0
|
90
92
|
|
91
93
|
case result
|
92
94
|
when :wait_readable
|
@@ -99,15 +101,15 @@ module Binaryen
|
|
99
101
|
end
|
100
102
|
|
101
103
|
output
|
104
|
+
ensure
|
105
|
+
pipe.close_read if close_read
|
102
106
|
end
|
103
107
|
|
104
|
-
def wait_or_kill(pid, timeout_checker
|
108
|
+
def wait_or_kill(pid, timeout_checker)
|
105
109
|
loop do
|
106
|
-
|
107
|
-
raise Timeout::Error, "timed out waiting on process" if remaining_time <= 0
|
110
|
+
timeout_checker.check!
|
108
111
|
|
109
112
|
if (_, status = Process.wait2(pid, Process::WNOHANG))
|
110
|
-
|
111
113
|
raise Binaryen::NonZeroExitStatus,
|
112
114
|
"command exited with status #{status.exitstatus}" if status.exitstatus != 0
|
113
115
|
|
data/lib/binaryen/version.rb
CHANGED