diff --git a/Utils.h b/Utils.h index be29cfbe..114ea1f3 100644 --- a/Utils.h +++ b/Utils.h @@ -108,7 +108,7 @@ public: Init(); } - void Open(const CString& sFile, bool bRw = false) { + bool Open(const CString& sFile, bool bRw = false) { Close(); m_fd = open(sFile.c_str(), bRw ? O_RDWR : O_RDONLY); @@ -117,6 +117,11 @@ public: if (m_fd == -1) { // I must create the file then m_fd = open(sFile.c_str(), O_RDWR|O_CREAT, 0644); + + if (m_fd == -1) { + return false; + } + m_bCreated = true; } @@ -125,6 +130,8 @@ public: m_pid = getpid(); // for destructor m_sFileName = sFile; + + return true; } //! timeout in milliseconds diff --git a/znc.cpp b/znc.cpp index a3e9bf52..04886824 100644 --- a/znc.cpp +++ b/znc.cpp @@ -903,7 +903,13 @@ bool CZNC::DoRehash(CString& sError) return false; } - if (!m_LockFile.TryExLock(m_sConfigFile)) { + if (!m_LockFile.Open(m_sConfigFile)) { + sError = "Can not open config file"; + CUtils::PrintStatus(false, sError); + return false; + } + + if (!m_LockFile.TryExLock()) { sError = "ZNC is already running on this config."; CUtils::PrintStatus(false, sError); return false;