From 9a1c3874bc4dca158ec6c0a78bf134153af252ab Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 8 Feb 2008 20:52:20 +0000 Subject: [PATCH] Remove the pid file when ZNC exits git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@948 726aef4b-f618-498e-8847-2d620e286838 --- znc.cpp | 22 ++++++++++++++++++++++ znc.h | 1 + 2 files changed, 23 insertions(+) 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);