Run ps with an ulimited width on linux

On some systems the output of ps may be truncated, which may prevent
profiles from working as intended.

Some implementations specifically mention that the output width is
undefined "(it may be 80, unlimited, determined by the TERM variable,
and so on)".

This fixes #5226.

Signed-off-by: Raphael Geissert <atomo64@gmail.com>
This commit is contained in:
Raphael Geissert 2020-08-31 15:30:43 +02:00
parent d00706b9a6
commit b2e62b5b2f
3 changed files with 3 additions and 3 deletions

View file

@ -138,7 +138,7 @@ module Inspec::Resources
command: 8, command: 8,
} }
else else
command = "ps axo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command" command = "ps wwaxo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command"
regex = /^(.+?)\s+(\d+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(\w{3} \d{2}|\d{2}:\d{2}:\d{2})\s+([^ ]+)\s+([^ ]+)\s+(.*)$/ regex = /^(.+?)\s+(\d+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+([^ ]+)\s+(\w{3} \d{2}|\d{2}:\d{2}:\d{2})\s+([^ ]+)\s+([^ ]+)\s+(.*)$/
field_map = { field_map = {
label: 1, label: 1,

View file

@ -210,7 +210,7 @@ class MockLoader
'find /sys/class/net/eth1/ -maxdepth 1 -type f -exec sh -c \'echo "[$(basename {})]"; cat {} || echo -n\' \;' => empty.call, 'find /sys/class/net/eth1/ -maxdepth 1 -type f -exec sh -c \'echo "[$(basename {})]"; cat {} || echo -n\' \;' => empty.call,
"Get-Package -Name 'Not available' | ConvertTo-Json" => empty.call, "Get-Package -Name 'Not available' | ConvertTo-Json" => empty.call,
"ps axo pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user,command" => cmd.call("ps-axo"), "ps axo pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user,command" => cmd.call("ps-axo"),
"ps axo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command" => cmd.call("ps-axoZ"), "ps wwaxo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command" => cmd.call("ps-axoZ"),
"ps -o pid,vsz,rss,tty,stat,time,ruser,args" => cmd.call("ps-busybox"), "ps -o pid,vsz,rss,tty,stat,time,ruser,args" => cmd.call("ps-busybox"),
"env" => cmd.call("env"), "env" => cmd.call("env"),
"${Env:PATH}" => cmd.call("$env-PATH"), "${Env:PATH}" => cmd.call("$env-PATH"),

View file

@ -228,6 +228,6 @@ describe "Inspec::Resources::Processes" do
it "returns the correct command for non-busybox linux" do it "returns the correct command for non-busybox linux" do
resource = MockLoader.new(:centos7).load_resource("processes") resource = MockLoader.new(:centos7).load_resource("processes")
resource.expects(:busybox_ps?).returns(false) resource.expects(:busybox_ps?).returns(false)
_(resource.send(:ps_configuration_for_linux)[0]).must_equal "ps axo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command" _(resource.send(:ps_configuration_for_linux)[0]).must_equal "ps wwaxo label,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,user:32,command"
end end
end end