mixlib-shellout 3.1.0-universal-mingw32 → 3.1.7-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92c5afe3e5855d00509b4572c17660939c989f18f78ac3a10c37557e4aee0c41
|
4
|
+
data.tar.gz: 6fe34230ee29d956efa30c718597836ef620ef5d0f6814fa7cf5f0c661796827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3b54ec98167f6206ff1f9d7448fb8884681bcc7196efca871fea743f75c2caea2860c893f235a190b5c38ce8fa66550a498f7450052884884f31d76fba5529f
|
7
|
+
data.tar.gz: 84773efd97d6e2f5b092d6209f041f3c7c9c72de9b946f39b9205c95e184f9e40ccda86fd6bb121d082539a7efb0468e424f77401922e72a51b10910d1ec96f1
|
data/lib/mixlib/shellout.rb
CHANGED
@@ -16,8 +16,8 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require "etc"
|
20
|
-
require "tmpdir"
|
19
|
+
require "etc" unless defined?(Etc)
|
20
|
+
require "tmpdir" unless defined?(Dir.mktmpdir)
|
21
21
|
require "fcntl"
|
22
22
|
require_relative "shellout/exceptions"
|
23
23
|
|
@@ -122,7 +122,7 @@ module Mixlib
|
|
122
122
|
# === Options:
|
123
123
|
# If the last argument is a Hash, it is removed from the list of args passed
|
124
124
|
# to exec and used as an options hash. The following options are available:
|
125
|
-
# * +user+: the user the
|
125
|
+
# * +user+: the user the command should run as. if an integer is given, it is
|
126
126
|
# used as a uid. A string is treated as a username and resolved to a uid
|
127
127
|
# with Etc.getpwnam
|
128
128
|
# * +group+: the group the command should run as. works similarly to +user+
|
@@ -248,7 +248,7 @@ module Mixlib
|
|
248
248
|
# running or died without setting an exit status (e.g., terminated by
|
249
249
|
# `kill -9`).
|
250
250
|
def exitstatus
|
251
|
-
@status
|
251
|
+
@status&.exitstatus
|
252
252
|
end
|
253
253
|
|
254
254
|
# Run the command, writing the command's standard out and standard error
|
@@ -16,33 +16,23 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
require_relative "../shellout"
|
19
|
-
require "chef-utils"
|
20
|
-
require "chef-utils/dsl/
|
19
|
+
require "chef-utils" unless defined?(ChefUtils)
|
20
|
+
require "chef-utils/dsl/default_paths"
|
21
21
|
require "chef-utils/internal"
|
22
22
|
|
23
23
|
module Mixlib
|
24
24
|
class ShellOut
|
25
25
|
module Helper
|
26
26
|
include ChefUtils::Internal
|
27
|
-
include ChefUtils::DSL::
|
27
|
+
include ChefUtils::DSL::DefaultPaths
|
28
28
|
|
29
|
-
# PREFERRED APIS:
|
30
29
|
#
|
31
|
-
#
|
30
|
+
# These APIs are considered public for use in ohai and chef (by cookbooks and plugins, etc)
|
31
|
+
# but are considered private/experimental for now for the direct users of mixlib-shellout.
|
32
32
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
|
38
|
-
# provider.shell_out!("foo", [ "bar", nil, "baz"])
|
39
|
-
# provider.shell_out!(["foo", nil, "bar" ], ["baz"])
|
40
|
-
#
|
41
|
-
# note that shell_out_compacted also includes adding the magical timeout option to force
|
42
|
-
# people to setup expectations on that value explicitly. it does not include the default_env
|
43
|
-
# mangling in order to avoid users having to setup an expectation on anything other than
|
44
|
-
# setting `default_env: false` and allow us to make tweak to the default_env without breaking
|
45
|
-
# a thousand unit tests.
|
33
|
+
# You can see an example of how to handle the "dependency injection" in the rspec unit test.
|
34
|
+
# That backend API is left deliberately undocumented for now and may not follow SemVer and may
|
35
|
+
# break at any time (at least for the rest of 2020).
|
46
36
|
#
|
47
37
|
|
48
38
|
def shell_out(*args, **options)
|
@@ -98,15 +88,28 @@ module Mixlib
|
|
98
88
|
"LC_ALL" => __config[:internal_locale],
|
99
89
|
"LANGUAGE" => __config[:internal_locale],
|
100
90
|
"LANG" => __config[:internal_locale],
|
101
|
-
__env_path_name =>
|
91
|
+
__env_path_name => default_paths,
|
102
92
|
}.update(options[env_key] || {})
|
103
93
|
end
|
104
94
|
options
|
105
95
|
end
|
106
96
|
|
107
|
-
#
|
97
|
+
# The shell_out_compacted/shell_out_compacted! APIs are private but are intended for use
|
98
|
+
# in rspec tests. They should always be used in rspec tests instead of shell_out to allow
|
99
|
+
# for less brittle rspec tests.
|
108
100
|
#
|
109
|
-
#
|
101
|
+
# This expectation:
|
102
|
+
#
|
103
|
+
# allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz")
|
104
|
+
#
|
105
|
+
# Is met by many different possible calling conventions that mean the same thing:
|
106
|
+
#
|
107
|
+
# provider.shell_out!("foo", [ "bar", nil, "baz"])
|
108
|
+
# provider.shell_out!(["foo", nil, "bar" ], ["baz"])
|
109
|
+
#
|
110
|
+
# Note that when setting `default_env: false` that you should just setup an expectation on
|
111
|
+
# :shell_out_compacted for `default_env: false`, rather than the expanded env settings so
|
112
|
+
# that the default_env implementation can change without breaking unit tests.
|
110
113
|
#
|
111
114
|
def shell_out_compacted(*args, **options)
|
112
115
|
options = __apply_default_env(options)
|
@@ -117,10 +120,6 @@ module Mixlib
|
|
117
120
|
end
|
118
121
|
end
|
119
122
|
|
120
|
-
# this SHOULD be used for setting up expectations in rspec, see banner comment at top.
|
121
|
-
#
|
122
|
-
# the private constraint is meant to avoid code calling this directly, rspec expectations are fine.
|
123
|
-
#
|
124
123
|
def shell_out_compacted!(*args, **options)
|
125
124
|
options = __apply_default_env(options)
|
126
125
|
cmd = if options.empty?
|
@@ -132,23 +131,12 @@ module Mixlib
|
|
132
131
|
cmd
|
133
132
|
end
|
134
133
|
|
135
|
-
# Helper for subclasses to reject nil out of an array. It allows
|
136
|
-
#
|
137
|
-
# quote marks to deal with shells).
|
138
|
-
#
|
139
|
-
# Usage:
|
140
|
-
# shell_out!(*clean_array("useradd", universal_options, useradd_options, new_resource.username))
|
141
|
-
#
|
142
|
-
# universal_options and useradd_options can be nil, empty array, empty string, strings or arrays
|
143
|
-
# and the result makes sense.
|
144
|
-
#
|
145
|
-
# keeping this separate from shell_out!() makes it a bit easier to write expectations against the
|
146
|
-
# shell_out args and be able to omit nils and such in the tests (and to test that the nils are
|
147
|
-
# being rejected correctly).
|
134
|
+
# Helper for subclasses to reject nil out of an array. It allows using the array form of
|
135
|
+
# shell_out (which avoids the need to surround arguments with quote marks to deal with shells).
|
148
136
|
#
|
149
137
|
# @param args [String] variable number of string arguments
|
150
138
|
# @return [Array] array of strings with nil and null string rejection
|
151
|
-
|
139
|
+
#
|
152
140
|
def __clean_array(*args)
|
153
141
|
args.flatten.compact.map(&:to_s)
|
154
142
|
end
|
@@ -169,7 +157,7 @@ module Mixlib
|
|
169
157
|
end
|
170
158
|
|
171
159
|
def __io_for_live_stream
|
172
|
-
if STDOUT.
|
160
|
+
if !STDOUT.closed? && __log.trace?
|
173
161
|
STDOUT
|
174
162
|
else
|
175
163
|
nil
|
data/lib/mixlib/shellout/unix.rb
CHANGED
@@ -370,11 +370,11 @@ module Mixlib
|
|
370
370
|
return if attempt_reap
|
371
371
|
|
372
372
|
@terminate_reason = "Command exceeded allowed execution time, process terminated"
|
373
|
-
logger
|
373
|
+
logger&.error("Command exceeded allowed execution time, sending TERM")
|
374
374
|
Process.kill(:TERM, child_pgid)
|
375
375
|
sleep 3
|
376
376
|
attempt_reap
|
377
|
-
logger
|
377
|
+
logger&.error("Command exceeded allowed execution time, sending KILL")
|
378
378
|
Process.kill(:KILL, child_pgid)
|
379
379
|
reap
|
380
380
|
|
@@ -89,7 +89,7 @@ module Mixlib
|
|
89
89
|
# Start the process
|
90
90
|
#
|
91
91
|
process, profile, token = Process.create3(create_process_args)
|
92
|
-
logger
|
92
|
+
logger&.debug(format_process(process, app_name, command_line, timeout))
|
93
93
|
begin
|
94
94
|
# Start pushing data into input
|
95
95
|
stdin_write << input if input
|
@@ -124,7 +124,7 @@ module Mixlib
|
|
124
124
|
kill_process_tree(process.process_id, wmi, logger)
|
125
125
|
Process.kill(:KILL, process.process_id)
|
126
126
|
rescue SystemCallError
|
127
|
-
logger
|
127
|
+
logger&.warn("Failed to kill timed out process #{process.process_id}")
|
128
128
|
end
|
129
129
|
|
130
130
|
raise Mixlib::ShellOut::CommandTimeout, [
|
@@ -208,7 +208,7 @@ module Mixlib
|
|
208
208
|
# 4. if the argument must be quoted by #1 and terminates in a sequence of backslashes then all the backlashes must themselves
|
209
209
|
# be backslash excaped (double the backslashes).
|
210
210
|
# 5. if an interior quote that must be escaped by #2 has a sequence of backslashes before it then all the backslashes must
|
211
|
-
# themselves be backslash excaped along with the backslash
|
211
|
+
# themselves be backslash excaped along with the backslash escape of the interior quote (double plus one backslashes).
|
212
212
|
#
|
213
213
|
# And to restate. We are constructing a string which will be parsed by the windows parser into arguments, and we want those
|
214
214
|
# arguments to match the *args array we are passed here. So call the windows parser operation A then we need to apply A^-1 to
|
@@ -398,20 +398,16 @@ module Mixlib
|
|
398
398
|
|
399
399
|
def kill_process(instance, logger)
|
400
400
|
child_pid = instance.wmi_ole_object.processid
|
401
|
-
|
402
|
-
logger.debug([
|
401
|
+
logger&.debug([
|
403
402
|
"killing child process #{child_pid}::",
|
404
403
|
"#{instance.wmi_ole_object.Name} of parent #{pid}",
|
405
404
|
].join)
|
406
|
-
end
|
407
405
|
Process.kill(:KILL, instance.wmi_ole_object.processid)
|
408
406
|
rescue SystemCallError
|
409
|
-
|
410
|
-
logger.debug([
|
407
|
+
logger&.debug([
|
411
408
|
"Failed to kill child process #{child_pid}::",
|
412
409
|
"#{instance.wmi_ole_object.Name} of parent #{pid}",
|
413
410
|
].join)
|
414
|
-
end
|
415
411
|
end
|
416
412
|
|
417
413
|
def format_process(process, app_name, command_line, timeout)
|
@@ -21,7 +21,6 @@ require "win32/process"
|
|
21
21
|
|
22
22
|
# Add new constants for Logon
|
23
23
|
module Process::Constants
|
24
|
-
private
|
25
24
|
|
26
25
|
LOGON32_LOGON_INTERACTIVE = 0x00000002
|
27
26
|
LOGON32_LOGON_BATCH = 0x00000004
|
@@ -148,15 +147,13 @@ module Process
|
|
148
147
|
si_hash = {}
|
149
148
|
|
150
149
|
# If the startup_info key is present, validate its subkeys
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
raise ArgumentError, "invalid startup_info key '#{key}'"
|
156
|
-
end
|
157
|
-
|
158
|
-
si_hash[key] = val
|
150
|
+
hash["startup_info"]&.each do |key, val|
|
151
|
+
key = key.to_s.downcase
|
152
|
+
unless valid_si_keys.include?(key)
|
153
|
+
raise ArgumentError, "invalid startup_info key '#{key}'"
|
159
154
|
end
|
155
|
+
|
156
|
+
si_hash[key] = val
|
160
157
|
end
|
161
158
|
|
162
159
|
# The +command_line+ key is mandatory unless the +app_name+ key
|
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: 3.1.
|
4
|
+
version: 3.1.7
|
5
5
|
platform: universal-mingw32
|
6
6
|
authors:
|
7
7
|
- Chef Software Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-utils
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: '0.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: '0.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: wmi-lite
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|