iso_latte 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iso_latte/version.rb +1 -1
- data/lib/iso_latte.rb +24 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 929b7df9ff0f59ee35cd1b20f0d861d37c8ebfef
|
4
|
+
data.tar.gz: 6288dd0d0dae3ca40bd5c91387def5961c3e55af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1e74442a0cf7f03bcf239eb84d0d3b18863f466e14592e099c8f3c16990d8b4764de49d70b6572442c4a7b611a199594ab11ce60805e948bfa0990e85241ed
|
7
|
+
data.tar.gz: 08c505d181c5945db613e60d1848d2988fbca6a9c7f888887b7fdbee0aa5af7c221845c57d98e67a7d8eea19e39f4fb911f6e2e829aba8a4b02c459c71127fe2
|
data/lib/iso_latte/version.rb
CHANGED
data/lib/iso_latte.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "ostruct"
|
2
|
+
require "timeout"
|
2
3
|
|
3
4
|
module IsoLatte
|
4
5
|
NO_EXIT = 122
|
@@ -16,6 +17,7 @@ module IsoLatte
|
|
16
17
|
# fault: a callable to execute if the subprocess segfaults, core dumps, etc.
|
17
18
|
# exit: a callable to execute if the subprocess voluntarily exits with nonzero.
|
18
19
|
# receives the exit status value as its argument.
|
20
|
+
# timeout: after this many seconds, the parent should send a SIGKILL to the child.
|
19
21
|
#
|
20
22
|
# It is allowable to Isolatte.fork from inside an IsoLatte.fork block (reentrant)
|
21
23
|
#
|
@@ -59,7 +61,17 @@ module IsoLatte
|
|
59
61
|
|
60
62
|
write_ex.close
|
61
63
|
|
62
|
-
pid, rc =
|
64
|
+
pid, rc =
|
65
|
+
begin
|
66
|
+
if opts.timeout
|
67
|
+
Timeout.timeout(opts.timeout) { Process.wait2(child_pid) }
|
68
|
+
else
|
69
|
+
Process.wait2(child_pid)
|
70
|
+
end
|
71
|
+
rescue Timeout::Error
|
72
|
+
kill_child(child_pid)
|
73
|
+
end
|
74
|
+
|
63
75
|
fail(Error, "Wrong child's exit received!") unless pid == child_pid
|
64
76
|
|
65
77
|
if rc.exited? && rc.exitstatus == EXCEPTION_RAISED
|
@@ -84,8 +96,18 @@ module IsoLatte
|
|
84
96
|
# *explicitly* exited, whether with zero or nonzero.
|
85
97
|
opts.exit.call(rc.exitstatus) if opts.exit && rc.exited? && rc.exitstatus != NO_EXIT
|
86
98
|
|
87
|
-
# This should execute
|
99
|
+
# This should execute regardless of the outcome
|
100
|
+
# (unless some other hook raises an exception first)
|
88
101
|
opts.finish.call(success, code) if opts.finish
|
102
|
+
|
103
|
+
rc
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.kill_child(pid)
|
107
|
+
Process.kill("KILL", pid)
|
108
|
+
Process.wait2(pid)
|
109
|
+
rescue Errno::ESRCH
|
110
|
+
# Save us from the race condition where it exited just as we decided to kill it.
|
89
111
|
end
|
90
112
|
|
91
113
|
class Error < StandardError; end
|