execute 0.1.39 → 0.1.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmd.rb +30 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38fb4647be1c94c5513f80514adde8b97b618eb9
4
- data.tar.gz: 02125021c9178df1f7c4944abdee1cd64c77b19e
3
+ metadata.gz: 061d92584632aa290c94c0b57161ad77951492ea
4
+ data.tar.gz: b76a1c1fe4ec10e05679e78e94d6c3b8e89cb714
5
5
  SHA512:
6
- metadata.gz: f85781a0f832f5bdb25cf4e880dcb659725fd826b1e1d74ca8f32f92a35d47a36212c11bbea3296eb08b9554245a4d567051d591713e11250266285aa4b19995
7
- data.tar.gz: 13d94191b6c1cb315871be2a637b0b9a18847e46947a17ce1d4f0e12f48c409df4e298e97cde22a6e12e6facb931303010a4d484bdbfdf13f9caa31f8f9f65b3
6
+ metadata.gz: 20a8bd82b602a3768b7a23e7a8527fca44b240ff5651071ed08839bf1760a64499fb4af2631582237a29856668e21ebc27d464393916bc3e5f6b037c6e8b48c8
7
+ data.tar.gz: 978cc09e2b15a4315110742343cd3d1ab37e16eab5dfbeae704052d459ccecd7fcb1c467d36885db52b833cae933c34f4e769f99b3c4bc6c9f1803d8085304fe
data/lib/cmd.rb CHANGED
@@ -12,6 +12,25 @@ class CMD < Hash
12
12
  self[:output] = ''
13
13
  self[:error] = ''
14
14
 
15
+ #1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
16
+ #5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
17
+ #9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
18
+ #13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
19
+ #18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
20
+ #22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
21
+ #26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
22
+ #30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1
23
+ #36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5
24
+ #40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9
25
+ #44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
26
+ #48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13
27
+ #52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9
28
+ #56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5
29
+ #60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1
30
+ #64) SIGRTMAX
31
+ self[:timeout_signal] = 9
32
+ self[:timeout_raise_error] = true
33
+
15
34
  @@default_options.each { |key, value| self[key] = value}
16
35
  options.each { |key, value| self[key] = value} unless(options.nil?)
17
36
  self[:command]=cmd
@@ -38,7 +57,8 @@ class CMD < Hash
38
57
  puts "exit_code: #{self[:exit_code]}"
39
58
  end
40
59
 
41
- raise TimeoutError.new(self[:command], self[:timeout]) if(key?(:timed_out))
60
+ raise TimeoutError.new(self[:command], self[:timeout]) if(key?(:timed_out) && self[:timeout_raise_error])
61
+
42
62
  if((self[:exit_code] != 0) && !self[:ignore_exit_code])
43
63
  exception_text = "Exit code: #{self[:exit_code]}"
44
64
  exception_text = "#{exception_text}\nError: '#{self[:error]}'"
@@ -64,7 +84,7 @@ class CMD < Hash
64
84
  sleep(0.1)
65
85
  if((Time.now - start_time).to_f > self[:timeout])
66
86
  self[:timed_out] = true
67
- Process.kill('KILL',wait_thr.pid)
87
+ interrupt
68
88
  sleep(0.1)
69
89
  end
70
90
  end
@@ -104,5 +124,12 @@ class CMD < Hash
104
124
  self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
105
125
  end
106
126
  end
107
- # Open3.capture3 hung on runas
127
+ def interrupt
128
+ process = []
129
+ Sys::ProcTable.ps { |p| process << p if(p.ppid == self[:pid]) }
130
+ Sys::ProcTable.ps { |p| process << p if(p.pid == self[:pid]) }
131
+
132
+ process.each { |p| Process.kill(self[:timeout_signal],p.pid) unless(Sys::ProcTable.ps(p.pid).nil?) }
133
+ Process.waitpid(self[:pid]) unless(Sys::ProcTable.ps(self[:pid]).nil?)
134
+ end
108
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.39
4
+ version: 0.1.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-12 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler