Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Patch ZNC core for more control over singleton...

  • Loading branch information...
commit 4c505946ac3c69913ada1e97bd9e8b10aeafba09 1 parent 200c5da
@KiNgMaR KiNgMaR authored
Showing with 24 additions and 8 deletions.
  1. +3 −1 include/znc/znc.h
  2. +4 −1 src/main.cpp
  3. +17 −6 src/znc.cpp
View
4 include/znc/znc.h
@@ -56,7 +56,7 @@ class CZNC {
CString ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir = true);
bool WriteNewConfig(const CString& sConfigFile);
bool WriteConfig();
- bool ParseConfig(const CString& sConfig);
+ bool ParseConfig(const CString& sConfig, CString& sError);
bool RehashConfig(CString& sError);
void BackupConfigOnce(const CString& sSuffix);
static CString GetVersion();
@@ -131,7 +131,9 @@ class CZNC {
// !Getters
// Static allocator
+ static void CreateInstance();
static CZNC& Get();
+ static void DestroyInstance();
CUser* FindUser(const CString& sUsername);
CModule* FindModule(const CString& sModName, const CString& sUsername);
CModule* FindModule(const CString& sModName, CUser* pUser);
View
5 src/main.cpp
@@ -193,6 +193,8 @@ int main(int argc, char** argv) {
return 1;
}
+ CZNC::CreateInstance();
+
CZNC* pZNC = &CZNC::Get();
pZNC->InitDirs(((argc) ? argv[0] : ""), sDataDir);
@@ -264,7 +266,8 @@ int main(int argc, char** argv) {
/* Fall through to normal bootup */
}
- if (!pZNC->ParseConfig(sConfig)) {
+ CString sConfigError;
+ if (!pZNC->ParseConfig(sConfig, sConfigError)) {
CUtils::PrintError("Unrecoverable config error.");
delete pZNC;
return 1;
View
23 src/znc.cpp
@@ -1022,13 +1022,11 @@ void CZNC::BackupConfigOnce(const CString& sSuffix) {
CUtils::PrintStatus(false, strerror(errno));
}
-bool CZNC::ParseConfig(const CString& sConfig)
+bool CZNC::ParseConfig(const CString& sConfig, CString& sError)
{
- CString s;
-
m_sConfigFile = ExpandConfigPath(sConfig, false);
- return DoRehash(s);
+ return DoRehash(sError);
}
bool CZNC::RehashConfig(CString& sError)
@@ -1853,9 +1851,22 @@ bool CZNC::DelListener(CListener* pListener) {
return false;
}
+static CZNC* s_pZNC = NULL;
+
+void CZNC::CreateInstance() {
+ if (s_pZNC)
+ abort();
+
+ s_pZNC = new CZNC();
+}
+
CZNC& CZNC::Get() {
- static CZNC* pZNC = new CZNC;
- return *pZNC;
+ return *s_pZNC;
+}
+
+void CZNC::DestroyInstance() {
+ delete s_pZNC;
+ s_pZNC = NULL;
}
CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users,
Please sign in to comment.
Something went wrong with that request. Please try again.