From fe361f7a1808b2999356987733b11351561f1c43 Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 29 Apr 2008 12:15:48 +0000 Subject: [PATCH] Display a better error message if znc.conf cannot be opened If znc.conf was a regular file which we just couldn't open (chmod 0), ZNC reported that it was already running on this config. This patch fixes this message. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1033 726aef4b-f618-498e-8847-2d620e286838 --- Utils.h | 9 ++++++++- znc.cpp | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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;