Lines 1-8
Link Here
|
|
|
1 |
Add system-wide daemon support. |
2 |
|
3 |
This patch adds system-wide daemon support to ZNC so that you can run |
4 |
one ZNC instance system-wide using the new "--system-wide-config-as" |
5 |
option. |
6 |
|
7 |
Patch is based on @mrueg version from 2012. |
8 |
|
9 |
X-Gentoo-Bug: 438430 |
10 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=438430 |
11 |
--- |
12 |
include/znc/znc.h | 3 ++ |
13 |
src/main.cpp | 83 ++++++++++++++++++++++++++++++++++++++++--------------- |
14 |
src/znc.cpp | 7 ++++- |
15 |
3 files changed, 70 insertions(+), 23 deletions(-) |
16 |
|
1 |
diff --git a/include/znc/znc.h b/include/znc/znc.h |
17 |
diff --git a/include/znc/znc.h b/include/znc/znc.h |
2 |
index 03be646..f493c83 100644 |
18 |
index cf2326e..16394f9 100644 |
3 |
--- a/include/znc/znc.h |
19 |
--- a/include/znc/znc.h |
4 |
+++ b/include/znc/znc.h |
20 |
+++ b/include/znc/znc.h |
5 |
@@ -169,6 +169,8 @@ public: |
21 |
@@ -187,6 +187,8 @@ public: |
6 |
|
22 |
|
7 |
static void DumpConfig(const CConfig* Config); |
23 |
static void DumpConfig(const CConfig* Config); |
8 |
|
24 |
|
Lines 11-47
index 03be646..f493c83 100644
Link Here
|
11 |
private: |
27 |
private: |
12 |
CFile* InitPidFile(); |
28 |
CFile* InitPidFile(); |
13 |
bool DoRehash(CString& sError); |
29 |
bool DoRehash(CString& sError); |
14 |
@@ -209,6 +211,7 @@ protected: |
30 |
@@ -231,6 +233,7 @@ protected: |
15 |
unsigned int m_uiConnectPaused; |
31 |
unsigned int m_uiConnectPaused; |
16 |
TCacheMap<CString> m_sConnectThrottle; |
32 |
TCacheMap<CString> m_sConnectThrottle; |
17 |
bool m_bProtectWebSessions; |
33 |
bool m_bProtectWebSessions; |
18 |
+ bool m_bSystemWideConfig; |
34 |
+ bool m_bSystemWideConfig; |
|
|
35 |
bool m_bHideVersion; |
19 |
}; |
36 |
}; |
20 |
|
37 |
|
21 |
#endif // !_ZNC_H |
|
|
22 |
diff --git a/src/main.cpp b/src/main.cpp |
38 |
diff --git a/src/main.cpp b/src/main.cpp |
23 |
index a1f3904..4950911 100644 |
39 |
index 09b2c9c..bd5cca6 100644 |
24 |
--- a/src/main.cpp |
40 |
--- a/src/main.cpp |
25 |
+++ b/src/main.cpp |
41 |
+++ b/src/main.cpp |
26 |
@@ -10,6 +10,9 @@ |
42 |
@@ -16,6 +16,9 @@ |
27 |
#include <znc/FileUtils.h> |
43 |
|
28 |
#include <sys/wait.h> |
44 |
#include <znc/znc.h> |
29 |
#include <signal.h> |
45 |
#include <signal.h> |
30 |
+#include <sys/types.h> |
46 |
+#include <sys/types.h> |
31 |
+#include <pwd.h> |
47 |
+#include <pwd.h> |
32 |
+#include <grp.h> |
48 |
+#include <grp.h> |
33 |
|
49 |
|
34 |
using std::cout; |
50 |
#if defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD) |
35 |
using std::endl; |
51 |
#include <znc/Threads.h> |
36 |
@@ -46,6 +49,7 @@ static const struct option g_LongOpts[] = { |
52 |
@@ -99,34 +102,36 @@ static inline int getopt_long(int argc, char * const argv[], const char *optstri |
37 |
{ "makepass", no_argument, 0, 's' }, |
53 |
#endif |
38 |
{ "makepem", no_argument, 0, 'p' }, |
54 |
|
39 |
{ "datadir", required_argument, 0, 'd' }, |
55 |
static const struct option g_LongOpts[] = { |
40 |
+ { "system-wide-config-as", required_argument, 0, 'S' }, |
56 |
- { "help", no_argument, 0, 'h' }, |
|
|
57 |
- { "version", no_argument, 0, 'v' }, |
58 |
- { "debug", no_argument, 0, 'D' }, |
59 |
- { "foreground", no_argument, 0, 'f' }, |
60 |
- { "no-color", no_argument, 0, 'n' }, |
61 |
- { "allow-root", no_argument, 0, 'r' }, |
62 |
- { "makeconf", no_argument, 0, 'c' }, |
63 |
- { "makepass", no_argument, 0, 's' }, |
64 |
- { "makepem", no_argument, 0, 'p' }, |
65 |
- { "datadir", required_argument, 0, 'd' }, |
66 |
+ { "help", no_argument, 0, 'h' }, |
67 |
+ { "version", no_argument, 0, 'v' }, |
68 |
+ { "debug", no_argument, 0, 'D' }, |
69 |
+ { "foreground", no_argument, 0, 'f' }, |
70 |
+ { "no-color", no_argument, 0, 'n' }, |
71 |
+ { "allow-root", no_argument, 0, 'r' }, |
72 |
+ { "makeconf", no_argument, 0, 'c' }, |
73 |
+ { "makepass", no_argument, 0, 's' }, |
74 |
+ { "makepem", no_argument, 0, 'p' }, |
75 |
+ { "datadir", required_argument, 0, 'd' }, |
76 |
+ { "system-wide-config-as", required_argument, 0, 'S' }, |
41 |
{ 0, 0, 0, 0 } |
77 |
{ 0, 0, 0, 0 } |
42 |
}; |
78 |
}; |
43 |
|
79 |
|
44 |
@@ -127,6 +131,8 @@ int main(int argc, char** argv) { |
80 |
static void GenerateHelp(const char *appname) { |
|
|
81 |
CUtils::PrintMessage("USAGE: " + CString(appname) + " [options]"); |
82 |
CUtils::PrintMessage("Options are:"); |
83 |
- CUtils::PrintMessage("\t-h, --help List available command line options (this page)"); |
84 |
- CUtils::PrintMessage("\t-v, --version Output version information and exit"); |
85 |
- CUtils::PrintMessage("\t-f, --foreground Don't fork into the background"); |
86 |
- CUtils::PrintMessage("\t-D, --debug Output debugging information (Implies -f)"); |
87 |
- CUtils::PrintMessage("\t-n, --no-color Don't use escape sequences in the output"); |
88 |
- CUtils::PrintMessage("\t-r, --allow-root Don't complain if ZNC is run as root"); |
89 |
- CUtils::PrintMessage("\t-c, --makeconf Interactively create a new config"); |
90 |
- CUtils::PrintMessage("\t-s, --makepass Generates a password for use in config"); |
91 |
+ CUtils::PrintMessage("\t-h, --help List available command line options (this page)"); |
92 |
+ CUtils::PrintMessage("\t-v, --version Output version information and exit"); |
93 |
+ CUtils::PrintMessage("\t-f, --foreground Don't fork into the background"); |
94 |
+ CUtils::PrintMessage("\t-D, --debug Output debugging information (Implies -f)"); |
95 |
+ CUtils::PrintMessage("\t-n, --no-color Don't use escape sequences in the output"); |
96 |
+ CUtils::PrintMessage("\t-r, --allow-root Don't complain if ZNC is run as root"); |
97 |
+ CUtils::PrintMessage("\t-c, --makeconf Interactively create a new config"); |
98 |
+ CUtils::PrintMessage("\t-s, --makepass Generates a password for use in config"); |
99 |
#ifdef HAVE_LIBSSL |
100 |
- CUtils::PrintMessage("\t-p, --makepem Generates a pemfile for use with SSL"); |
101 |
+ CUtils::PrintMessage("\t-p, --makepem Generates a pemfile for use with SSL"); |
102 |
#endif /* HAVE_LIBSSL */ |
103 |
- CUtils::PrintMessage("\t-d, --datadir Set a different ZNC repository (default is ~/.znc)"); |
104 |
+ CUtils::PrintMessage("\t-d, --datadir Set a different ZNC repository (default is ~/.znc)"); |
105 |
+ CUtils::PrintMessage("\t-S, --system-wide-config-as Create a system-wide ZNC daemon configuration"); |
106 |
} |
107 |
|
108 |
static void die(int sig) { |
109 |
@@ -192,6 +197,8 @@ int main(int argc, char** argv) { |
45 |
bool bMakeConf = false; |
110 |
bool bMakeConf = false; |
46 |
bool bMakePass = false; |
111 |
bool bMakePass = false; |
47 |
bool bAllowRoot = false; |
112 |
bool bAllowRoot = false; |
Lines 50-65
index a1f3904..4950911 100644
Link Here
|
50 |
bool bForeground = false; |
115 |
bool bForeground = false; |
51 |
#ifdef ALWAYS_RUN_IN_FOREGROUND |
116 |
#ifdef ALWAYS_RUN_IN_FOREGROUND |
52 |
bForeground = true; |
117 |
bForeground = true; |
53 |
@@ -135,7 +141,7 @@ int main(int argc, char** argv) { |
118 |
@@ -201,7 +208,7 @@ int main(int argc, char** argv) { |
54 |
bool bMakePem = false; |
|
|
55 |
#endif |
119 |
#endif |
|
|
120 |
CZNC::CreateInstance(); |
56 |
|
121 |
|
57 |
- while ((iArg = getopt_long(argc, argv, "hvnrcspd:Df", g_LongOpts, &iOptIndex)) != -1) { |
122 |
- while ((iArg = getopt_long(argc, argv, "hvnrcspd:Df", g_LongOpts, &iOptIndex)) != -1) { |
58 |
+ while ((iArg = getopt_long(argc, argv, "hvnrcspd:DfS:", g_LongOpts, &iOptIndex)) != -1) { |
123 |
+ while ((iArg = getopt_long(argc, argv, "hvnrcspd:DfS:", g_LongOpts, &iOptIndex)) != -1) { |
59 |
switch (iArg) { |
124 |
switch (iArg) { |
60 |
case 'h': |
125 |
case 'h': |
61 |
GenerateHelp(argv[0]); |
126 |
GenerateHelp(argv[0]); |
62 |
@@ -153,6 +159,10 @@ int main(int argc, char** argv) { |
127 |
@@ -219,6 +226,10 @@ int main(int argc, char** argv) { |
63 |
case 'c': |
128 |
case 'c': |
64 |
bMakeConf = true; |
129 |
bMakeConf = true; |
65 |
break; |
130 |
break; |
Lines 70-76
index a1f3904..4950911 100644
Link Here
|
70 |
case 's': |
135 |
case 's': |
71 |
bMakePass = true; |
136 |
bMakePass = true; |
72 |
break; |
137 |
break; |
73 |
@@ -187,8 +197,36 @@ int main(int argc, char** argv) { |
138 |
@@ -254,8 +265,36 @@ int main(int argc, char** argv) { |
74 |
return 1; |
139 |
return 1; |
75 |
} |
140 |
} |
76 |
|
141 |
|
Lines 107-113
index a1f3904..4950911 100644
Link Here
|
107 |
|
172 |
|
108 |
#ifdef HAVE_LIBSSL |
173 |
#ifdef HAVE_LIBSSL |
109 |
if (bMakePem) { |
174 |
if (bMakePem) { |
110 |
@@ -229,7 +267,7 @@ int main(int argc, char** argv) { |
175 |
@@ -304,7 +343,7 @@ int main(int argc, char** argv) { |
111 |
CUtils::PrintStatus(true, ""); |
176 |
CUtils::PrintStatus(true, ""); |
112 |
} |
177 |
} |
113 |
|
178 |
|
Lines 117-134
index a1f3904..4950911 100644
Link Here
|
117 |
CUtils::PrintError("reasons for this and it can, in theory, cause great damage!"); |
182 |
CUtils::PrintError("reasons for this and it can, in theory, cause great damage!"); |
118 |
if (!bAllowRoot) { |
183 |
if (!bAllowRoot) { |
119 |
diff --git a/src/znc.cpp b/src/znc.cpp |
184 |
diff --git a/src/znc.cpp b/src/znc.cpp |
120 |
index 9469790..297b021 100644 |
185 |
index 78cda1a..b33e860 100644 |
121 |
--- a/src/znc.cpp |
186 |
--- a/src/znc.cpp |
122 |
+++ b/src/znc.cpp |
187 |
+++ b/src/znc.cpp |
123 |
@@ -47,6 +47,7 @@ CZNC::CZNC() { |
188 |
@@ -55,6 +55,7 @@ CZNC::CZNC() { |
124 |
m_sConnectThrottle.SetTTL(30000); |
189 |
m_sConnectThrottle.SetTTL(30000); |
125 |
m_pLockFile = NULL; |
190 |
m_pLockFile = NULL; |
126 |
m_bProtectWebSessions = true; |
191 |
m_bProtectWebSessions = true; |
127 |
+ m_bSystemWideConfig = false; |
192 |
+ m_bSystemWideConfig = false; |
128 |
} |
193 |
m_bHideVersion = false; |
129 |
|
194 |
m_uDisabledSSLProtocols = Csock::EDP_SSL; |
130 |
CZNC::~CZNC() { |
195 |
m_sSSLProtocols = ""; |
131 |
@@ -952,7 +953,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { |
196 |
@@ -861,7 +862,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) { |
132 |
CUtils::PrintMessage(""); |
197 |
CUtils::PrintMessage(""); |
133 |
|
198 |
|
134 |
File.UnLock(); |
199 |
File.UnLock(); |
Lines 136-143
index 9469790..297b021 100644
Link Here
|
136 |
+ return bFileOpen && !m_bSystemWideConfig && CUtils::GetBoolInput("Launch ZNC now?", true); |
201 |
+ return bFileOpen && !m_bSystemWideConfig && CUtils::GetBoolInput("Launch ZNC now?", true); |
137 |
} |
202 |
} |
138 |
|
203 |
|
139 |
size_t CZNC::FilterUncommonModules(set<CModInfo>& ssModules) { |
204 |
void CZNC::BackupConfigOnce(const CString& sSuffix) { |
140 |
@@ -1971,3 +1972,7 @@ void CZNC::LeakConnectQueueTimer(CConnectQueueTimer *pTimer) { |
205 |
@@ -1973,3 +1974,7 @@ void CZNC::LeakConnectQueueTimer(CConnectQueueTimer *pTimer) { |
141 |
bool CZNC::WaitForChildLock() { |
206 |
bool CZNC::WaitForChildLock() { |
142 |
return m_pLockFile && m_pLockFile->ExLock(); |
207 |
return m_pLockFile && m_pLockFile->ExLock(); |
143 |
} |
208 |
} |
Lines 145-147
index 9469790..297b021 100644
Link Here
|
145 |
+void CZNC::SetSystemWideConfig(bool systemWideConfig) { |
210 |
+void CZNC::SetSystemWideConfig(bool systemWideConfig) { |
146 |
+ m_bSystemWideConfig = systemWideConfig; |
211 |
+ m_bSystemWideConfig = systemWideConfig; |
147 |
+} |
212 |
+} |
|
|
213 |
-- |
214 |
2.5.0 |
215 |
|