diff options
author | Dave Nicponski <dave.nicponski@gmail.com> | 2022-08-07 10:13:11 -0400 |
---|---|---|
committer | Dave Nicponski <dave.nicponski@gmail.com> | 2022-08-07 10:13:11 -0400 |
commit | cb6794a0d983eb364601f26fc32ead98ed67bfb4 (patch) | |
tree | 2169d4b6d52a904e4c45247b33aa0c8f42583b14 | |
parent | 6776e65fd960e25b55d11a03324f9007b6dc2a0b (diff) |
Do not spam logs if the owned-homedir check results in a noop
-rw-r--r-- | src/libutil/util.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index be6fe091f..e11cb9c60 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -577,6 +577,7 @@ Path getHome() { static Path homeDir = []() { + std::optional<std::string> unownedUserHomeDir = {}; auto homeDir = getEnv("HOME"); if (homeDir) { // Only use $HOME if doesn't exist or is owned by the current user. @@ -588,8 +589,7 @@ Path getHome() homeDir.reset(); } } else if (st.st_uid != geteuid()) { - warn("$HOME ('%s') is not owned by you, falling back to the one defined in the 'passwd' file", *homeDir); - homeDir.reset(); + unownedUserHomeDir.swap(homeDir); } } if (!homeDir) { @@ -600,6 +600,9 @@ Path getHome() || !pw || !pw->pw_dir || !pw->pw_dir[0]) throw Error("cannot determine user's home directory"); homeDir = pw->pw_dir; + if (unownedUserHomeDir.has_value() && unownedUserHomeDir != homeDir) { + warn("$HOME ('%s') is not owned by you, falling back to the one defined in the 'passwd' file ('%s')", *unownedUserHomeDir, *homeDir); + } } return *homeDir; }(); |