From cadfabc3b1b7ff068637b9c81d41d6369731ec30 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 11 Sep 2022 08:49:08 +0200 Subject: [PATCH] pathut: give $HOME priority over pwd entry --- src/utils/pathut.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 689fa307..4e78e876 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -666,19 +666,16 @@ string path_home() path_catslash(dir); return dir; #else - uid_t uid = getuid(); - - struct passwd *entry = getpwuid(uid); - if (entry == 0) { - const char *cp = getenv("HOME"); - if (cp) { - return cp; - } else { + const char *cp = getenv("HOME"); + if (nullptr == cp) { + uid_t uid = getuid(); + struct passwd *entry = getpwuid(uid); + if (nullptr == entry) { return "/"; } + cp = entry->pw_dir; } - - string homedir = entry->pw_dir; + string homedir{cp}; path_catslash(homedir); return homedir; #endif