summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian C. Dunn <jdunn@aquezada.com>2014-08-15 15:12:29 -0400
committerJulian C. Dunn <jdunn@aquezada.com>2014-08-15 15:12:29 -0400
commit28dcc46ceae73b5ff22e72735db182ffa1e3a574 (patch)
tree3793a9bc4ca4ebbdbbc3212a832d3ae85e9fcaf2
parenta8bd2e029ed93bda256ce23cc166927cf0549b3e (diff)
parentfec9467a0c93b203e97447207352745536c2b471 (diff)
downloadohai-28dcc46ceae73b5ff22e72735db182ffa1e3a574.tar.gz
Merge pull request #386 from juliandunn/getlogin-lies
getlogin() often lies, especially when run under "su"
-rw-r--r--lib/ohai/plugins/passwd.rb2
-rw-r--r--spec/unit/plugins/passwd_spec.rb3
2 files changed, 3 insertions, 2 deletions
diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb
index 1e10f708..9a5cd06f 100644
--- a/lib/ohai/plugins/passwd.rb
+++ b/lib/ohai/plugins/passwd.rb
@@ -32,7 +32,7 @@ Ohai.plugin(:Passwd) do
end
unless current_user
- current_user fix_encoding(Etc.getlogin)
+ current_user fix_encoding(Etc.getpwuid(Process.euid).name)
end
end
end
diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb
index 33b57005..335ba6b7 100644
--- a/spec/unit/plugins/passwd_spec.rb
+++ b/spec/unit/plugins/passwd_spec.rb
@@ -24,7 +24,8 @@ describe Ohai::System, "plugin etc" do
end
it "should set the current user" do
- Etc.should_receive(:getlogin).and_return('chef')
+ Process.should_receive(:euid).and_return('31337')
+ Etc.should_receive(:getpwuid).and_return(PasswdEntry.new('chef', 31337, 31337, '/home/chef', '/bin/ksh', 'Julia Child'))
@plugin.run
@plugin[:current_user].should == 'chef'
end