summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mixlib/shellout.rb4
-rw-r--r--lib/mixlib/shellout/unix.rb4
-rw-r--r--lib/mixlib/shellout/version.rb2
-rw-r--r--lib/mixlib/shellout/windows.rb54
-rw-r--r--lib/mixlib/shellout/windows/core_ext.rb12
5 files changed, 48 insertions, 28 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index 6f8730f..2fdbcfd 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -1,6 +1,6 @@
#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2010, 2011 Opscode, Inc.
+# Author:: Daniel DeLeo (<dan@chef.io>)
+# Copyright:: Copyright (c) 2010-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index dd22cbe..734a597 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -1,6 +1,6 @@
#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2010, 2011 Opscode, Inc.
+# Author:: Daniel DeLeo (<dan@chef.io>)
+# Copyright:: Copyright (c) 2010-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/mixlib/shellout/version.rb b/lib/mixlib/shellout/version.rb
index b8f65e8..e59d531 100644
--- a/lib/mixlib/shellout/version.rb
+++ b/lib/mixlib/shellout/version.rb
@@ -1,5 +1,5 @@
module Mixlib
class ShellOut
- VERSION = "2.2.5"
+ VERSION = "2.2.7"
end
end
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb
index 14aca55..5b13dad 100644
--- a/lib/mixlib/shellout/windows.rb
+++ b/lib/mixlib/shellout/windows.rb
@@ -1,8 +1,8 @@
#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Author:: John Keiser (<jkeiser@opscode.com>)
-# Author:: Ho-Sheng Hsiao (<hosh@opscode.com>)
-# Copyright:: Copyright (c) 2011, 2012 Opscode, Inc.
+# Author:: Daniel DeLeo (<dan@chef.io>)
+# Author:: John Keiser (<jkeiser@chef.io>)
+# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
+# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -321,31 +321,51 @@ module Mixlib
File.executable?(path) && !File.directory?(path)
end
+ def self.system_required_processes
+ [
+ 'System Idle Process',
+ 'System',
+ 'spoolsv.exe',
+ 'lsass.exe',
+ 'csrss.exe',
+ 'smss.exe',
+ 'svchost.exe'
+ ]
+ end
+
+ def self.unsafe_process?(name, logger)
+ return false unless system_required_processes.include? name
+ logger.debug(
+ "A request to kill a critical system process - #{name} - was received and skipped."
+ )
+ true
+ end
+
# recursively kills all child processes of given pid
# calls itself querying for children child procs until
# none remain. Important that a single WmiLite instance
# is passed in since each creates its own WMI rpc process
def self.kill_process_tree(pid, wmi, logger)
wmi.query("select * from Win32_Process where ParentProcessID=#{pid}").each do |instance|
+ next if unsafe_process?(instance.wmi_ole_object.name, logger)
child_pid = instance.wmi_ole_object.processid
kill_process_tree(child_pid, wmi, logger)
- begin
- logger.debug([
- "killing child process #{child_pid}::",
- "#{instance.wmi_ole_object.Name} of parent #{pid}"
- ].join) if logger
- kill_process(instance)
- rescue Errno::EIO, SystemCallError
- logger.debug([
- "Failed to kill child process #{child_pid}::",
- "#{instance.wmi_ole_object.Name} of parent #{pid}"
- ].join) if logger
- end
+ kill_process(instance, logger)
end
end
- def self.kill_process(instance)
+ def self.kill_process(instance, logger)
+ child_pid = instance.wmi_ole_object.processid
+ logger.debug([
+ "killing child process #{child_pid}::",
+ "#{instance.wmi_ole_object.Name} of parent #{pid}"
+ ].join) if logger
Process.kill(:KILL, instance.wmi_ole_object.processid)
+ rescue Errno::EIO, SystemCallError
+ logger.debug([
+ "Failed to kill child process #{child_pid}::",
+ "#{instance.wmi_ole_object.Name} of parent #{pid}"
+ ].join) if logger
end
def self.format_process(process, app_name, command_line, timeout)
diff --git a/lib/mixlib/shellout/windows/core_ext.rb b/lib/mixlib/shellout/windows/core_ext.rb
index d889778..2fe2bf2 100644
--- a/lib/mixlib/shellout/windows/core_ext.rb
+++ b/lib/mixlib/shellout/windows/core_ext.rb
@@ -1,7 +1,7 @@
#--
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Author:: John Keiser (<jkeiser@opscode.com>)
-# Copyright:: Copyright (c) 2011, 2012 Opscode, Inc.
+# Author:: Daniel DeLeo (<dan@chef.io>)
+# Author:: John Keiser (<jkeiser@chef.io>)
+# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,7 +42,7 @@ module Process::Functions
[:buffer_in, :buffer_in, :buffer_in, :ulong, :ulong, :pointer], :bool
attach_pfunc :CreateProcessAsUserW,
- [:ulong, :buffer_in, :buffer_in, :pointer, :pointer, :bool,
+ [:ulong, :buffer_in, :buffer_inout, :pointer, :pointer, :int,
:ulong, :buffer_in, :buffer_in, :pointer, :pointer], :bool
ffi_lib :user32
@@ -268,8 +268,8 @@ module Process
# If running in the service windows station must do a log on to get
# to the interactive desktop. Running process user account must have
# the 'Replace a process level token' permission. This is necessary as
- # the logon (which happens with CreateProcessWithLogon) must have an
- # interactive windows station to attach to, which is created with the
+ # the logon (which happens with CreateProcessWithLogon) must have an
+ # interactive windows station to attach to, which is created with the
# LogonUser cann with the LOGON32_LOGON_INTERACTIVE flag.
if winsta_name =~ /^Service-0x0-.*$/i
token = FFI::MemoryPointer.new(:ulong)