Skip to content

Commit

Permalink
Fixes the systemd? check for pre Linux 2.6.33 kernels
Browse files Browse the repository at this point in the history
/proc/<pid>/comm was introduced in linux 2.6.33
  • Loading branch information
jeroenj committed Sep 15, 2016
1 parent ba19837 commit 15df350
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/chef/sugar/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module Init
# @return [Boolean]
#
def systemd?(node)
IO.read('/proc/1/comm').chomp == 'systemd'
file = '/proc/1/comm'
File.exist?(file) && IO.read(file).chomp == 'systemd'
end

#
Expand Down
11 changes: 10 additions & 1 deletion spec/unit/chef/sugar/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
.and_return("systemd")

node = {}
expect(described_class.systemd?(node)).to be true
expect(described_class.systemd?(node)).to be true
end

it 'is false when /proc/1/comm is not systemd' do
node = {}
expect(described_class.systemd?(node)).to be false
end

it 'is false when /proc/1/comm does not exist' do
allow(File).to receive(:exist?)
.with("/proc/1/comm")
.and_return(false)

node = {}
expect(described_class.systemd?(node)).to be false
end
end

describe '#upstart?' do
Expand Down

0 comments on commit 15df350

Please sign in to comment.