summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2015-12-14 11:25:42 -0800
committerTim Smith <tsmith@chef.io>2015-12-14 11:25:42 -0800
commitf92837521b6d5ac973322cae09dfdb7a4932e931 (patch)
treeb1880bf4a00d04e7147fbcaa04e0b93a96542888
parent975d8e7186484a4208034fef5ad42b8ae22d3fac (diff)
parenteb18e6877a243e4b84aab2ebdcdef8e53a0cba7e (diff)
downloadohai-f92837521b6d5ac973322cae09dfdb7a4932e931.tar.gz
Merge pull request #683 from tas50/old_init
Handle old kernels where we can't determine the init system
-rw-r--r--lib/ohai/plugins/init_package.rb10
-rw-r--r--spec/unit/plugins/init_package_spec.rb12
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/ohai/plugins/init_package.rb b/lib/ohai/plugins/init_package.rb
index ec7dc1ac..5f38a361 100644
--- a/lib/ohai/plugins/init_package.rb
+++ b/lib/ohai/plugins/init_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# Copyright:: Copyright (c) 2012-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,12 +20,6 @@ Ohai.plugin(:InitPackage) do
provides "init_package"
collect_data(:linux) do
- package_name = nil
-
- if File.exists?("/proc/1/comm")
- package_name = File.open("/proc/1/comm").gets.chomp
- end
-
- init_package package_name
+ init_package File.exists?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : 'init'
end
end
diff --git a/spec/unit/plugins/init_package_spec.rb b/spec/unit/plugins/init_package_spec.rb
index 5a64ed13..c78538f3 100644
--- a/spec/unit/plugins/init_package_spec.rb
+++ b/spec/unit/plugins/init_package_spec.rb
@@ -26,11 +26,12 @@ describe Ohai::System, "Init package" do
}
let(:proc1_content) { "init\n" }
+ let(:proc1_exists) { true }
let(:proc_1_file_path) { "/proc/1/comm" }
let(:proc_1_file) { double(proc_1_file_path, :gets => proc1_content) }
before(:each) do
- allow(File).to receive(:exists?).with(proc_1_file_path).and_return(true)
+ allow(File).to receive(:exists?).with(proc_1_file_path).and_return(proc1_exists)
allow(File).to receive(:open).with(proc_1_file_path).and_return(proc_1_file)
end
@@ -47,4 +48,13 @@ describe Ohai::System, "Init package" do
expect(plugin[:init_package]).to eq("systemd")
end
end
+
+ describe "when /proc/1/comm doesn't exist" do
+ let(:proc1_exists) { false }
+
+ it "should set init_package to init" do
+ plugin.run
+ expect(plugin[:init_package]).to eq("init")
+ end
+ end
end