Fix issue where absent HOME would break Dir.home

Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
This commit is contained in:
Vivek Singh 2020-11-27 20:33:09 +05:30
parent 8a608dac76
commit 896e5fa261

View file

@ -1,11 +1,20 @@
require_relative "utils/install_context" require_relative "utils/install_context"
require 'etc' unless defined?(Etc)
module Inspec module Inspec
extend Inspec::InstallContextHelpers extend Inspec::InstallContextHelpers
def self.config_dir def self.config_dir
ENV["INSPEC_CONFIG_DIR"] ? ENV["INSPEC_CONFIG_DIR"] : File.join(Dir.home, ".inspec") begin
home = Dir.home
rescue ArgumentError, NoMethodError
# $HOME is not set in systemd service File.expand_path('~') will not work here
home = Etc.getpwuid(Process.uid).dir
end
ENV["INSPEC_CONFIG_DIR"] ? ENV["INSPEC_CONFIG_DIR"] : File.join(home, ".inspec")
end end
def self.src_root def self.src_root