Greg Clayton via llvm-dev
2016-Apr-19 18:18 UTC
[llvm-dev] llvm::sys::path::home_directory() implementation for unix
I recently was using llvm code from a process that I manually spawned as a child process and noticed that llvm::sys::path::home_directory() only works if "HOME" is set in the process environment: bool home_directory(SmallVectorImpl<char> &result) { if (char *RequestedDir = getenv("HOME")) { result.clear(); result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); return true; } return false; } This is in lib/Support/Unix/Path.inc. Do we want to try a little bit harder? Maybe something like: bool home_directory(SmallVectorImpl<char> &result) { if (char *RequestedDir = getenv("HOME")) { result.clear(); result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); return true; } else { struct passwd *pw = getpwuid(getuid()); if (pw && pw->pw_dir && pw->pw_dir[0]) { setenv("HOME", pw->pw_dir, 0); result.assign(llvm::StringRef(pw->pw_dir)); return true; } } return false; }
Sean Silva via llvm-dev
2016-Apr-20 06:51 UTC
[llvm-dev] llvm::sys::path::home_directory() implementation for unix
We probably don't want to silently mutate the environment (which could lead to surprises), but calling a proper system library function to get the home directory makes sense. -- Sean Silva On Tue, Apr 19, 2016 at 11:18 AM, Greg Clayton via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I recently was using llvm code from a process that I manually spawned as a > child process and noticed that llvm::sys::path::home_directory() only works > if "HOME" is set in the process environment: > > bool home_directory(SmallVectorImpl<char> &result) { > if (char *RequestedDir = getenv("HOME")) { > result.clear(); > result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); > return true; > } > > return false; > } > > This is in lib/Support/Unix/Path.inc. Do we want to try a little bit > harder? Maybe something like: > > bool home_directory(SmallVectorImpl<char> &result) { > if (char *RequestedDir = getenv("HOME")) { > result.clear(); > result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); > return true; > } else { > struct passwd *pw = getpwuid(getuid()); > if (pw && pw->pw_dir && pw->pw_dir[0]) > { > setenv("HOME", pw->pw_dir, 0); > result.assign(llvm::StringRef(pw->pw_dir)); > return true; > } > } > return false; > } > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160419/e1ba512f/attachment.html>
Paweł Bylica via llvm-dev
2016-Apr-20 16:29 UTC
[llvm-dev] llvm::sys::path::home_directory() implementation for unix
Hi there, The issue has been discussed before, in case of this patch http://reviews.llvm.org/D14446. Some see this issue as a feature to disable access to home directory. I'm happy to implement whatever we agree on. - Paweł On Wed, Apr 20, 2016 at 8:51 AM Sean Silva via llvm-dev < llvm-dev at lists.llvm.org> wrote:> We probably don't want to silently mutate the environment (which could > lead to surprises), but calling a proper system library function to get the > home directory makes sense. > > -- Sean Silva > > On Tue, Apr 19, 2016 at 11:18 AM, Greg Clayton via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I recently was using llvm code from a process that I manually spawned as >> a child process and noticed that llvm::sys::path::home_directory() only >> works if "HOME" is set in the process environment: >> >> bool home_directory(SmallVectorImpl<char> &result) { >> if (char *RequestedDir = getenv("HOME")) { >> result.clear(); >> result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); >> return true; >> } >> >> return false; >> } >> >> This is in lib/Support/Unix/Path.inc. Do we want to try a little bit >> harder? Maybe something like: >> >> bool home_directory(SmallVectorImpl<char> &result) { >> if (char *RequestedDir = getenv("HOME")) { >> result.clear(); >> result.append(RequestedDir, RequestedDir + strlen(RequestedDir)); >> return true; >> } else { >> struct passwd *pw = getpwuid(getuid()); >> if (pw && pw->pw_dir && pw->pw_dir[0]) >> { >> setenv("HOME", pw->pw_dir, 0); >> result.assign(llvm::StringRef(pw->pw_dir)); >> return true; >> } >> } >> return false; >> } >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160420/c7981236/attachment.html>