Commit b45c4803 authored by Committed by Craig SmallBrowse files
top: Do not default to the cwd in configs_read().
If the HOME environment variable is not set, or not absolute, use the home directory returned by getpwuid(getuid()), if set and absolute (instead of the cwd "."); otherwise, set p_home to NULL. To keep the changes to a minimum, we rely on POSIX, which requires that fopen() fails with ENOENT if the pathname (Rc_name) is an empty string. This integrates well into the existing code, and makes write_rcfile() work without a change. Also, it makes the code in configs_read() easier to follow: only set and use p_home if safe, and only set Rc_name if safe (in all the other cases it is the empty string, and the fopen() calls fail). Plus, check for snprintf() truncation (and if it happens, reset Rc_name to the empty string). Important note: top.1 should probably be updated, since it mentions the fallback to the current working directory.
Showing with 28 additions and 5 deletions