From 46f6651ba12ef94d35e64940f8bdabde926f6780 Mon Sep 17 00:00:00 2001 From: psychon Date: Thu, 21 Feb 2008 16:40:14 +0000 Subject: [PATCH] Try to get the user's home (~) from the env ($HOME) by default git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@966 726aef4b-f618-498e-8847-2d620e286838 --- znc.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/znc.cpp b/znc.cpp index cabc71ea..d6993cba 100644 --- a/znc.cpp +++ b/znc.cpp @@ -376,6 +376,8 @@ bool CZNC::IsHostAllowed(const CString& sHostMask) { void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) { char buf[PATH_MAX]; + char *home; + if (getcwd(buf, PATH_MAX) == NULL) { CUtils::PrintError("getcwd() failed, can't read my current dir"); exit(-1); @@ -386,10 +388,16 @@ void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) { m_sCurPath = (uPos == CString::npos) ? CString(buf) : CUtils::ChangeDir(buf, sArgvPath.substr(0, uPos), ""); // Try to set the user's home dir, default to binpath on failure - struct passwd* pUserInfo = getpwuid(getuid()); + home = getenv("HOME"); - if (pUserInfo) { - m_sHomePath = pUserInfo->pw_dir; + if (home) { + m_sHomePath = home; + } else { + struct passwd* pUserInfo = getpwuid(getuid()); + + if (pUserInfo) { + m_sHomePath = pUserInfo->pw_dir; + } } if (m_sHomePath.empty()) {