mixlib-shellout 2.2.2 → 2.2.3

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: 304f772cea76b9913e4354ee216f9171d89df4b0
4
- data.tar.gz: a6d5cf525447578c32e64aaed36d64a322e103e4
3
+ metadata.gz: b4bc17fff8cee2442b8d414c7d05b375c136496b
4
+ data.tar.gz: 4ddd98eac40ec5f6ac45325662e768752c542f51
5
5
  SHA512:
6
- metadata.gz: 69933eb3b6dbb1f9877e1b1c7eacd3062426d30482917217b597584241e2c0582cbc3822a3e35e81248ab2b1c2ec1c492bdc72fe6724a98f43ed6d68d33d8f3e
7
- data.tar.gz: 2333d801858fa0a2dffca808a900ca7d0570dfeb5acc889914eb91f03c4f3a9d7b5d1dba31456b904d1d37570e1e2bf3cecb3fecdd1fb8c4f6c64e798f1209fc
6
+ metadata.gz: be5543b10efabb6cb3ed54cf977616624b7b7b7fefaf3ad5e7aa354c583254b378c3b8423575348d92832e79ad92b2b90463086820948dd2a91a078a16293cc1
7
+ data.tar.gz: af9a2b0c953e05c00d94e9b4f80a92c1ca29dbcccab448af91f63ce0c34d8f0190a2ece6ba6cc08136f26099c409a975f48f2e954758b5676c96caefbca42069
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "2.2.2"
3
+ VERSION = "2.2.3"
4
4
  end
5
5
  end
@@ -43,7 +43,6 @@ module Mixlib
43
43
  # Missing lots of features from the UNIX version, such as
44
44
  # uid, etc.
45
45
  def run_command
46
-
47
46
  #
48
47
  # Create pipes to capture stdout and stderr,
49
48
  #
@@ -79,6 +78,7 @@ module Mixlib
79
78
  # Start the process
80
79
  #
81
80
  process = Process.create(create_process_args)
81
+ logger.debug(Utils.format_process(process, app_name, command_line, timeout)) if logger
82
82
  begin
83
83
  # Start pushing data into input
84
84
  stdin_write << input if input
@@ -107,12 +107,19 @@ module Mixlib
107
107
  # Kill the process
108
108
  if (Time.now - start_wait) > timeout
109
109
  begin
110
+ require 'wmi-lite/wmi'
111
+ wmi = WmiLite::Wmi.new
112
+ Utils.kill_process_tree(process.process_id, wmi, logger)
110
113
  Process.kill(:KILL, process.process_id)
111
- rescue Errno::EIO
114
+ rescue Errno::EIO, SystemCallError
112
115
  logger.warn("Failed to kill timed out process #{process.process_id}") if logger
113
116
  end
114
117
 
115
- raise Mixlib::ShellOut::CommandTimeout, "command timed out:\n#{format_for_exception}"
118
+ raise Mixlib::ShellOut::CommandTimeout, [
119
+ "command timed out:",
120
+ format_for_exception,
121
+ Utils.format_process(process, app_name, command_line, timeout)
122
+ ].join("\n")
116
123
  end
117
124
 
118
125
  consume_output(open_streams, stdout_read, stderr_read)
@@ -313,6 +320,42 @@ module Mixlib
313
320
  def self.executable?(path)
314
321
  File.executable?(path) && !File.directory?(path)
315
322
  end
323
+
324
+ # recursively kills all child processes of given pid
325
+ # calls itself querying for children child procs until
326
+ # none remain. Important that a single WmiLite instance
327
+ # is passed in since each creates its own WMI rpc process
328
+ def self.kill_process_tree(pid, wmi, logger)
329
+ wmi.query("select * from Win32_Process where ParentProcessID=#{pid}").each do |instance|
330
+ child_pid = instance.wmi_ole_object.processid
331
+ kill_process_tree(child_pid, wmi, logger)
332
+ begin
333
+ logger.debug([
334
+ "killing child process #{child_pid}::",
335
+ "#{instance.wmi_ole_object.Name} of parent #{pid}"
336
+ ].join) if logger
337
+ kill_process(instance)
338
+ rescue Errno::EIO, SystemCallError
339
+ logger.debug([
340
+ "Failed to kill child process #{child_pid}::",
341
+ "#{instance.wmi_ole_object.Name} of parent #{pid}"
342
+ ].join) if logger
343
+ end
344
+ end
345
+ end
346
+
347
+ def self.kill_process(instance)
348
+ Process.kill(:KILL, instance.wmi_ole_object.processid)
349
+ end
350
+
351
+ def self.format_process(process, app_name, command_line, timeout)
352
+ msg = []
353
+ msg << "ProcessId: #{process.process_id}"
354
+ msg << "app_name: #{app_name}"
355
+ msg << "command_line: #{command_line}"
356
+ msg << "timeout: #{timeout}"
357
+ msg.join("\n")
358
+ end
316
359
  end
317
360
  end # class
318
361
  end
@@ -3,5 +3,6 @@ gemspec = eval(File.read(File.expand_path("../mixlib-shellout.gemspec", __FILE__
3
3
  gemspec.platform = Gem::Platform.new(["universal", "mingw32"])
4
4
 
5
5
  gemspec.add_dependency "win32-process", "~> 0.8.2"
6
+ gemspec.add_dependency "wmi-lite", "~> 1.0"
6
7
 
7
8
  gemspec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Opscode
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -63,8 +63,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project:
66
- rubygems_version: 2.4.6
66
+ rubygems_version: 2.4.8
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Run external commands on Unix or Windows
70
70
  test_files: []
71
+ has_rdoc: