diff --git a/main.cpp b/main.cpp index 9caf94cf..61e9cc85 100644 --- a/main.cpp +++ b/main.cpp @@ -54,6 +54,10 @@ static void die(int sig) { exit(sig); } +static void rehash(int sig) { + CZNC::Get().SetNeedRehash(true); +} + int main(int argc, char** argv) { CString sConfig; CString sDataDir = ""; @@ -241,6 +245,9 @@ int main(int argc, char** argv) { sigaction(SIGSEGV, &sa, (struct sigaction*) NULL); sigaction(SIGTERM, &sa, (struct sigaction*) NULL); + sa.sa_handler = rehash; + sigaction(SIGHUP, &sa, (struct sigaction*) NULL); + int iRet = 0; try { diff --git a/znc.cpp b/znc.cpp index 39fffcfe..491452f0 100644 --- a/znc.cpp +++ b/znc.cpp @@ -23,6 +23,7 @@ CZNC::CZNC() { m_uBytesRead = 0; m_uBytesWritten = 0; m_pConnectUserTimer = NULL; + m_bNeedRehash = false; } CZNC::~CZNC() { @@ -176,6 +177,28 @@ bool CZNC::HandleUserDeletion() int CZNC::Loop() { while (true) { + CString sError; + map::iterator it; + map::iterator end; + + if (GetNeedRehash()) { + SetNeedRehash(false); + + bool b = RehashConfig(sError); + + end = m_msUsers.end(); + for (it = m_msUsers.begin(); it != end; it++) { + if (it->second->IsAdmin()) { + if (b) { + it->second->PutStatus("Rehashing succeeded"); + } else { + it->second->PutStatus("Rehashing failed: " + sError); + it->second->PutStatus("ZNC is in some possibly inconsistent state!"); + } + } + } + } + // Check for users that need to be deleted if (HandleUserDeletion()) { // Also remove those user(s) from the config file diff --git a/znc.h b/znc.h index bcd37d79..ebdc2a6e 100644 --- a/znc.h +++ b/znc.h @@ -124,12 +124,14 @@ public: void UpdateTrafficStats(); // Setters + void SetNeedRehash(bool b) { m_bNeedRehash = b; } void SetStatusPrefix(const CString& s) { m_sStatusPrefix = (s.empty()) ? "*" : s; } void SetISpoofFile(const CString& s) { m_sISpoofFile = s; } void SetISpoofFormat(const CString& s) { m_sISpoofFormat = (s.empty()) ? "global { reply \"%\" }" : s; } // !Setters // Getters + bool GetNeedRehash() { return m_bNeedRehash; } CSockManager& GetManager() { return m_Manager; } #ifdef _MODULES CGlobalModules& GetModules() { return *m_pModules; } @@ -177,7 +179,9 @@ private: bool DoRehash(CString& sError); // Returns true if something was done bool HandleUserDeletion(); + protected: + bool m_bNeedRehash; vector m_vpListeners; map m_msUsers; map m_msDelUsers;