gaqzi / gocd-cli

A command line interface for common Go tasks
MIT License
24 stars 8 forks source link

Doesn't get the correct path to config file when running as a subprocess with incorrectly set $HOME #8

Closed gaqzi closed 8 years ago

gaqzi commented 8 years ago

I'm running a check with Nagios and when being scheduled through NRPE it tries to read the config file from the home directory of the root user instead of the nagios user that NRPE is running as.

My guess is that this happens because the $HOME environment variable doesn't get re-initialized properly when NRPE daemonizes/starts.

As long as $HOME is set at all Python won't check with the OS where the user's home folder is. See the documentation for os.path.expanduser, and unless it's given the path in ~user/some/path format it won't figure out who the current user is.

My plan will be to:

  1. Current OS is Windows
    1. Use os.path.expanduser
  2. Current OS is not Windows:
    1. Figure out what the UID running the script is os.geteuid
    2. Get the home path from passwd database, pwd
    3. If that fails fallback to os.path.expanduser