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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5780f40ea4f18590135725740fccd26e885510fd
4
- data.tar.gz: 3201f17dad3af7bf0be4ae3b42596601f7c9b62a
3
+ metadata.gz: 929b7df9ff0f59ee35cd1b20f0d861d37c8ebfef
4
+ data.tar.gz: 6288dd0d0dae3ca40bd5c91387def5961c3e55af
5
5
  SHA512:
6
- metadata.gz: 86beb89d8fcfb691d81748deb32169fbf4aa41aa4c43c0cccfd49d901f25c5dfa2430588f44e2cc2986013aa73975a64ae1aec5104096ce98a2c7bde780ee91a
7
- data.tar.gz: fe992f6f80a746bcdbd5287d77c760498a221a8c5be79d8cdcf8ad960b9f9d957f4a7a16e78ccbb39c3f1fc72eaec714557e73800f11ef6d5eb62af724ee91b5
6
+ metadata.gz: bb1e74442a0cf7f03bcf239eb84d0d3b18863f466e14592e099c8f3c16990d8b4764de49d70b6572442c4a7b611a199594ab11ce60805e948bfa0990e85241ed
7
+ data.tar.gz: 08c505d181c5945db613e60d1848d2988fbca6a9c7f888887b7fdbee0aa5af7c221845c57d98e67a7d8eea19e39f4fb911f6e2e829aba8a4b02c459c71127fe2
@@ -1,3 +1,3 @@
1
1
  module IsoLatte
2
- VERSION = "1.0"
2
+ VERSION = "1.1"
3
3
  end
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 = Process.wait2(child_pid)
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 *no matter what*
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso_latte
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emcien Engineering