mixlib-shellout 3.3.6-x64-mingw-ucrt → 3.3.8-x64-mingw-ucrt

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: 710d00705678cc8dcb2d9b3d5ae03bc634ec804c5485335d8f2f5f578b88e0c2
4
- data.tar.gz: a10e9845000ceac048c84b0fe7001a4feb595a0170be08ecaba980e9a1dd9457
3
+ metadata.gz: b84ca3d9ea62bbabc402ac741dcda9eff32495378a27c27fa0ec0fef6076b887
4
+ data.tar.gz: 8cc11e8c014e0b77d67b273c6117d4163b09f5e7614850873dd8f9d62168fd56
5
5
  SHA512:
6
- metadata.gz: 8f43f70a7a51239804ca8cd9cd369b09e756573c69d4baaadabe6eaf5be7406f5601d38b3cecb6b1bf407a05ea2e82016dd86bc88c5f396271b52130f5fa6aba
7
- data.tar.gz: 04544a4060ed97f9129f34d17d68c2bf798d9f929be6dd9d32213decf9fd0b37006d65b5f63ec032eb565bb6541b01f6b3ea9bf125f7390ce19fddef07199572
6
+ metadata.gz: b0bee8a9ff62a013149b920b10f7eda9d51bc2d65345ecca5b5c3e449cc462dbe3addb161f1c8953372ffb4093aaf40db148296ce21b7acba84b1c01b39c8bd7
7
+ data.tar.gz: 909d566f81db461a35287e82cac8c3a5595046bda3c305c7deb2ed2f97ff5408f54d116c709fab5b2aa61d26ab28e5c4382204b3dcf90b606890d111aa45301f
@@ -16,6 +16,8 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require "fileutils" unless defined?(FileUtils)
20
+
19
21
  module Mixlib
20
22
  class ShellOut
21
23
  module Unix
@@ -131,7 +133,7 @@ module Mixlib
131
133
  reap_errant_child if should_reap?
132
134
  # make one more pass to get the last of the output after the
133
135
  # child process dies
134
- attempt_buffer_read
136
+ attempt_buffer_read(0)
135
137
  # no matter what happens, turn the GC back on, and hope whatever busted
136
138
  # version of ruby we're on doesn't allocate some objects during the next
137
139
  # GC run.
@@ -176,6 +178,16 @@ module Mixlib
176
178
  Dir.chdir(cwd) if cwd
177
179
  end
178
180
 
181
+ def set_cgroup
182
+ new_cgroup_path = "/sys/fs/cgroup/#{cgroup}"
183
+ # Create cgroup if missing
184
+ unless Dir.exist?(new_cgroup_path)
185
+ FileUtils.mkdir_p new_cgroup_path
186
+ end
187
+ # Migrate current process to newly cgroup, any subprocesses will run inside new cgroup
188
+ File.write("#{new_cgroup_path}/cgroup.procs", Process.pid.to_s)
189
+ end
190
+
179
191
  # Since we call setsid the child_pgid will be the child_pid, set to negative here
180
192
  # so it can be directly used in arguments to kill, wait, etc.
181
193
  def child_pgid
@@ -265,8 +277,8 @@ module Mixlib
265
277
  child_stdin.close # Kick things off
266
278
  end
267
279
 
268
- def attempt_buffer_read
269
- ready = IO.select(open_pipes, nil, nil, READ_WAIT_TIME)
280
+ def attempt_buffer_read(timeout = READ_WAIT_TIME)
281
+ ready = IO.select(open_pipes, nil, nil, timeout)
270
282
  if ready
271
283
  read_stdout_to_buffer if ready.first.include?(child_stdout)
272
284
  read_stderr_to_buffer if ready.first.include?(child_stderr)
@@ -304,6 +316,10 @@ module Mixlib
304
316
  open_pipes.delete(child_process_status)
305
317
  end
306
318
 
319
+ def cgroupv2_available?
320
+ File.read("/proc/mounts").match?(%r{^cgroup2 /sys/fs/cgroup})
321
+ end
322
+
307
323
  def fork_subprocess
308
324
  initialize_ipc
309
325
 
@@ -321,6 +337,10 @@ module Mixlib
321
337
 
322
338
  configure_subprocess_file_descriptors
323
339
 
340
+ if cgroup && cgroupv2_available?
341
+ set_cgroup
342
+ end
343
+
324
344
  set_secondarygroups
325
345
  set_group
326
346
  set_user
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.3.6".freeze
3
+ VERSION = "3.3.8".freeze
4
4
  end
5
5
  end
@@ -114,6 +114,9 @@ module Mixlib
114
114
 
115
115
  attr_accessor :sensitive
116
116
 
117
+ # Path to cgroupv2 that the process should run on
118
+ attr_accessor :cgroup
119
+
117
120
  # === Arguments:
118
121
  # Takes a single command, or a list of command fragments. These are used
119
122
  # as arguments to Kernel.exec. See the Kernel.exec documentation for more
@@ -179,6 +182,7 @@ module Mixlib
179
182
  @timeout = nil
180
183
  @elevated = false
181
184
  @sensitive = false
185
+ @cgroup = nil
182
186
 
183
187
  if command_args.last.is_a?(Hash)
184
188
  parse_options(command_args.pop)
@@ -303,7 +307,8 @@ module Mixlib
303
307
  def inspect
304
308
  "<#{self.class.name}##{object_id}: command: '#{@command}' process_status: #{@status.inspect} " +
305
309
  "stdout: '#{stdout.strip}' stderr: '#{stderr.strip}' child_pid: #{@child_pid.inspect} " +
306
- "environment: #{@environment.inspect} timeout: #{timeout} user: #{@user} group: #{@group} working_dir: #{@cwd} >"
310
+ "environment: #{@environment.inspect} timeout: #{timeout} user: #{@user} group: #{@group} working_dir: #{@cwd} " +
311
+ "cgroup: #{@cgroup} >"
307
312
  end
308
313
 
309
314
  private
@@ -354,6 +359,8 @@ module Mixlib
354
359
  self.elevated = setting
355
360
  when "sensitive"
356
361
  self.sensitive = setting
362
+ when "cgroup"
363
+ self.cgroup = setting
357
364
  else
358
365
  raise InvalidCommandOption, "option '#{option.inspect}' is not a valid option for #{self.class.name}"
359
366
  end
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.3.6
4
+ version: 3.3.8
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Chef Software Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-15 00:00:00.000000000 Z
11
+ date: 2025-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-utils