delano/sysinfo — pull request #3 by jperville (2014-02-12 09:01:21+00:00)
Title: Use `Etc.getpwuid` to depend less on environment variables being present.

This pull requests improves sysinfo by using the `/etc/passwd` functions from stdlib's `etc` library rather than relying on environment variables such as `$USER` and `$HOME` or `$TMPDIR`. When the user attributes can not be guessed using `Etc.getpwuid` then we still fallback to the environment variable method.

# Why?

I wrote a Ruby application that uses the `rye` ssh wrapper. My application works just fine when I run it manually but when I run it through upstart (which has limited environment variables) `rye` will not load my ssh keys (because it scanned the current directory for keys rather than `~/.ssh/id_*sa`). Since the `rye` code resolves the user's home directory using `sysinfo` I'm creating my pull request here.

# How to reproduce

By using `env -i` to run sysinfo with a clean environment.

```sh
$ env -i HOME=/home/dummy PATH=$PATH bundle exec ruby -Ilib -rsysinfo -e "puts SysInfo.new.home"
/home/dummy # <-- uses whatever is the value of $HOME
$ env HOME='' PATH=$PATH bundle exec ruby -Ilib -rsysinfo -e "puts SysInfo.new.home"
/home/julien/sysinfo # <-- broken, we want the home directory, not the current directory
$ env -i PATH=$PATH bundle exec ruby -Ilib -rsysinfo -e "puts SysInfo.new.home"
/home/julien/sysinfo/lib/sysinfo.rb:193:in `expand_path': can't convert nil into String (TypeError)
from /home/julien/sysinfo/lib/sysinfo.rb:193:in `home_ruby_unix'
from /home/julien/sysinfo/lib/sysinfo.rb:168:in `execute_platform_specific'
from /home/julien/sysinfo/lib/sysinfo.rb:152:in `home'
from -e:1:in `

'
```