diff --git a/znc.cpp b/znc.cpp index d186568a..ee9e4252 100644 --- a/znc.cpp +++ b/znc.cpp @@ -53,6 +53,8 @@ CZNC::~CZNC() { #ifdef _MODULES delete m_pModules; #endif + + DeletePidFile(); } CString CZNC::GetTag(bool bIncludeVersion) { @@ -263,6 +265,26 @@ bool CZNC::WritePidFile(int iPid) { return false; } +bool CZNC::DeletePidFile() { + if (!m_sPidFile.empty()) { + CString sFile; + // absolute path or relative to the data dir? + if (m_sPidFile[0] != '/') + sFile = GetZNCPath() + "/" + m_sPidFile; + else + sFile = m_sPidFile; + + CFile File(sFile); + CUtils::PrintAction("Deleting pid file [" + sFile + "]"); + if (File.Delete()) { + CUtils::PrintStatus(true); + return true; + } + CUtils::PrintStatus(false); + } + return false; +} + bool CZNC::WritePemFile( bool bEncPem ) { #ifndef HAVE_LIBSSL CUtils::PrintError("ZNC was not compiled with ssl support."); diff --git a/znc.h b/znc.h index 559cb051..2bd7db25 100644 --- a/znc.h +++ b/znc.h @@ -97,6 +97,7 @@ public: bool WriteISpoof(CUser* pUser); void ReleaseISpoof(); bool WritePidFile(int iPid); + bool DeletePidFile(); CUser* GetUser(const CString& sUser); Csock* FindSockByName(const CString& sSockName); bool ParseConfig(const CString& sConfig);