mirror of
https://github.com/znc/znc.git
synced 2026-07-21 09:03:32 +02:00
Added pid checking
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@174 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifdef _MODULES
|
#ifdef _MODULES
|
||||||
@@ -125,6 +126,46 @@ void CZNC::ReleaseISpoof() {
|
|||||||
m_bISpoofLocked = false;
|
m_bISpoofLocked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CZNC::SetPidFile(const string& sFile) {
|
||||||
|
CUtils::PrintAction("Checking PidFile [" + sFile + "]");
|
||||||
|
|
||||||
|
if (!sFile.empty() && sFile[0] != '/') {
|
||||||
|
m_sPidFile = GetZNCPath() + "/" + sFile;
|
||||||
|
} else {
|
||||||
|
m_sPidFile = sFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_sPidFile.empty()) {
|
||||||
|
unsigned int uPid = 0;
|
||||||
|
CFile File(m_sPidFile);
|
||||||
|
|
||||||
|
if (File.Open(O_RDONLY)) {
|
||||||
|
string sPid;
|
||||||
|
|
||||||
|
if (File.ReadLine(sPid)) {
|
||||||
|
uPid = atoi(sPid.c_str());
|
||||||
|
|
||||||
|
if (uPid > 0 && kill(uPid, 0) == 0) {
|
||||||
|
CUtils::PrintStatus(false, "ZNC already running [pid: " + CUtils::ToString(uPid) + "]");
|
||||||
|
File.Close();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
CUtils::PrintStatus(true, "Stale pid, relaunching");
|
||||||
|
File.Close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CUtils::PrintStatus(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CZNC::WritePidFile(int iPid) {
|
bool CZNC::WritePidFile(int iPid) {
|
||||||
if (!m_sPidFile.empty()) {
|
if (!m_sPidFile.empty()) {
|
||||||
CFile File(m_sPidFile);
|
CFile File(m_sPidFile);
|
||||||
@@ -485,10 +526,10 @@ bool CZNC::ParseConfig(const string& sConfigFile) {
|
|||||||
m_sISpoofFile = sValue;
|
m_sISpoofFile = sValue;
|
||||||
continue;
|
continue;
|
||||||
} else if (strcasecmp(sName.c_str(), "PidFile") == 0) {
|
} else if (strcasecmp(sName.c_str(), "PidFile") == 0) {
|
||||||
if (!sValue.empty() && sValue[0] != '/') {
|
if (!sValue.empty()) {
|
||||||
m_sPidFile = GetZNCPath() + "/" + sValue;
|
if (!SetPidFile(sValue)) {
|
||||||
} else {
|
return false;
|
||||||
m_sPidFile = sValue;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
void DeleteUsers();
|
void DeleteUsers();
|
||||||
int Loop();
|
int Loop();
|
||||||
void ReleaseISpoof();
|
void ReleaseISpoof();
|
||||||
|
bool SetPidFile(const string& sFile);
|
||||||
bool WritePidFile(int iPid);
|
bool WritePidFile(int iPid);
|
||||||
CUser* GetUser(const string& sUser);
|
CUser* GetUser(const string& sUser);
|
||||||
Csock* FindSockByName(const string& sSockName);
|
Csock* FindSockByName(const string& sSockName);
|
||||||
|
|||||||
Reference in New Issue
Block a user