|
@@ -0,0 +1,243 @@
|
|
1
|
+--- a/include/common.h
|
|
2
|
++++ b/include/common.h
|
|
3
|
+@@ -1081,4 +1081,7 @@ int parse_serveractive_element(char *str
|
|
4
|
+ #define ZBX_SESSION_ACTIVE 0
|
|
5
|
+ #define ZBX_SESSION_PASSIVE 1
|
|
6
|
+
|
|
7
|
++#define ZBX_RUN_BACKGROUND 0
|
|
8
|
++#define ZBX_RUN_FOREGROUND 1
|
|
9
|
++
|
|
10
|
+ #endif
|
|
11
|
+--- a/include/daemon.h
|
|
12
|
++++ b/include/daemon.h
|
|
13
|
+@@ -28,7 +28,7 @@ extern char *CONFIG_PID_FILE;
|
|
14
|
+
|
|
15
|
+ #include "threads.h"
|
|
16
|
+
|
|
17
|
+-int daemon_start(int allow_root, const char *user);
|
|
18
|
++int daemon_start(int allow_root, const char *user, int run_foreground);
|
|
19
|
+ void daemon_stop();
|
|
20
|
+
|
|
21
|
+ int zbx_sigusr_send(int flags);
|
|
22
|
+@@ -36,6 +36,6 @@ int zbx_sigusr_send(int flags);
|
|
23
|
+ #define ZBX_IS_RUNNING() 1
|
|
24
|
+ #define ZBX_DO_EXIT()
|
|
25
|
+
|
|
26
|
+-#define START_MAIN_ZABBIX_ENTRY(a, u) daemon_start(a, u)
|
|
27
|
++#define START_MAIN_ZABBIX_ENTRY(a, u, f) daemon_start(a, u, f)
|
|
28
|
+
|
|
29
|
+ #endif /* ZABBIX_DAEMON_H */
|
|
30
|
+--- a/src/libs/zbxnix/daemon.c
|
|
31
|
++++ b/src/libs/zbxnix/daemon.c
|
|
32
|
+@@ -272,16 +272,17 @@ static void set_daemon_signal_handlers()
|
|
33
|
+ * *
|
|
34
|
+ * Purpose: init process as daemon *
|
|
35
|
+ * *
|
|
36
|
+- * Parameters: allow_root - allow root permission for application *
|
|
37
|
+- * user - user on the system to which to drop the *
|
|
38
|
+- * privileges *
|
|
39
|
++ * Parameters: allow_root - allow root permission for application *
|
|
40
|
++ * user - user on the system to which to drop the *
|
|
41
|
++ * privileges *
|
|
42
|
++ * run_foreground - should it close its controling tty *
|
|
43
|
+ * *
|
|
44
|
+ * Author: Alexei Vladishev *
|
|
45
|
+ * *
|
|
46
|
+ * Comments: it doesn't allow running under 'root' if allow_root is zero *
|
|
47
|
+ * *
|
|
48
|
+ ******************************************************************************/
|
|
49
|
+-int daemon_start(int allow_root, const char *user)
|
|
50
|
++int daemon_start(int allow_root, const char *user, int run_foreground)
|
|
51
|
+ {
|
|
52
|
+ pid_t pid;
|
|
53
|
+ struct passwd *pwd;
|
|
54
|
+@@ -336,15 +337,22 @@ int daemon_start(int allow_root, const c
|
|
55
|
+ #endif
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+- if (0 != (pid = zbx_fork()))
|
|
59
|
+- exit(EXIT_SUCCESS);
|
|
60
|
++ if ( ZBX_RUN_FOREGROUND != run_foreground)
|
|
61
|
++ if (0 != (pid = zbx_fork()))
|
|
62
|
++ exit(EXIT_SUCCESS);
|
|
63
|
+
|
|
64
|
+ setsid();
|
|
65
|
+
|
|
66
|
+ signal(SIGHUP, SIG_IGN);
|
|
67
|
+
|
|
68
|
+- if (0 != (pid = zbx_fork()))
|
|
69
|
+- exit(EXIT_SUCCESS);
|
|
70
|
++ if ( ZBX_RUN_FOREGROUND == run_foreground) {
|
|
71
|
++ zabbix_log(LOG_LEVEL_INFORMATION, "Running in foreground...");
|
|
72
|
++ } else {
|
|
73
|
++ if (0 != (pid = zbx_fork()))
|
|
74
|
++ exit(EXIT_SUCCESS);
|
|
75
|
++ }
|
|
76
|
++
|
|
77
|
++
|
|
78
|
+
|
|
79
|
+ if (-1 == chdir("/")) /* this is to eliminate warning: ignoring return value of chdir */
|
|
80
|
+ assert(0);
|
|
81
|
+--- a/src/zabbix_agent/zabbix_agentd.c
|
|
82
|
++++ b/src/zabbix_agent/zabbix_agentd.c
|
|
83
|
+@@ -62,6 +62,8 @@ const char *progname = NULL;
|
|
84
|
+ static char DEFAULT_CONFIG_FILE[] = SYSCONFDIR "/zabbix_agentd.conf";
|
|
85
|
+ #endif
|
|
86
|
+
|
|
87
|
++int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
|
|
88
|
++
|
|
89
|
+ /* application TITLE */
|
|
90
|
+ const char title_message[] = APPLICATION_NAME
|
|
91
|
+ #if defined(_WIN64)
|
|
92
|
+@@ -93,6 +95,7 @@ const char usage_message[] =
|
|
93
|
+ const char *help_message[] = {
|
|
94
|
+ "Options:",
|
|
95
|
+ " -c --config <config-file> Absolute path to the configuration file",
|
|
96
|
++ " -f --foreground Run in foreground don't fork",
|
|
97
|
+ " -p --print Print known items and exit",
|
|
98
|
+ " -t --test <item key> Test specified item and exit",
|
|
99
|
+ " -h --help Display help information",
|
|
100
|
+@@ -127,6 +130,7 @@ const char *help_message[] = {
|
|
101
|
+ /* COMMAND LINE OPTIONS */
|
|
102
|
+ static struct zbx_option longopts[] =
|
|
103
|
+ {
|
|
104
|
++ {"foreground", 0, NULL, 'f'},
|
|
105
|
+ {"config", 1, NULL, 'c'},
|
|
106
|
+ {"help", 0, NULL, 'h'},
|
|
107
|
+ {"version", 0, NULL, 'V'},
|
|
108
|
+@@ -147,7 +151,7 @@ static struct zbx_option longopts[] =
|
|
109
|
+ };
|
|
110
|
+
|
|
111
|
+ static char shortopts[] =
|
|
112
|
+- "c:hVpt:"
|
|
113
|
++ "c:hfVpt:"
|
|
114
|
+ #ifndef _WINDOWS
|
|
115
|
+ "R:"
|
|
116
|
+ #else
|
|
117
|
+@@ -241,6 +245,9 @@ static void parse_commandline(int argc,
|
|
118
|
+ {
|
|
119
|
+ switch (ch)
|
|
120
|
+ {
|
|
121
|
++ case 'f':
|
|
122
|
++ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
|
|
123
|
++ break;
|
|
124
|
+ case 'c':
|
|
125
|
+ CONFIG_FILE = strdup(zbx_optarg);
|
|
126
|
+ break;
|
|
127
|
+@@ -944,7 +951,7 @@ int main(int argc, char **argv)
|
|
128
|
+ break;
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+- START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER);
|
|
132
|
++ START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
|
|
133
|
+
|
|
134
|
+ exit(EXIT_SUCCESS);
|
|
135
|
+ }
|
|
136
|
+--- a/src/zabbix_proxy/proxy.c
|
|
137
|
++++ b/src/zabbix_proxy/proxy.c
|
|
138
|
+@@ -60,6 +60,7 @@ const char usage_message[] = "[-hV] [-c
|
|
139
|
+
|
|
140
|
+ const char *help_message[] = {
|
|
141
|
+ "Options:",
|
|
142
|
++ " -f --foreground Run in foreground don't fork",
|
|
143
|
+ " -c --config <file> Absolute path to the configuration file",
|
|
144
|
+ " -R --runtime-control <option> Perform administrative functions",
|
|
145
|
+ "",
|
|
146
|
+@@ -84,6 +85,7 @@ const char *help_message[] = {
|
|
147
|
+ /* long options */
|
|
148
|
+ static struct zbx_option longopts[] =
|
|
149
|
+ {
|
|
150
|
++ {"foreground", 0, NULL, 'f'},
|
|
151
|
+ {"config", 1, NULL, 'c'},
|
|
152
|
+ {"runtime-control", 1, NULL, 'R'},
|
|
153
|
+ {"help", 0, NULL, 'h'},
|
|
154
|
+@@ -92,7 +94,7 @@ static struct zbx_option longopts[] =
|
|
155
|
+ };
|
|
156
|
+
|
|
157
|
+ /* short options */
|
|
158
|
+-static char shortopts[] = "c:n:hVR:";
|
|
159
|
++static char shortopts[] = "c:n:fhVR:";
|
|
160
|
+
|
|
161
|
+ /* end of COMMAND LINE OPTIONS */
|
|
162
|
+
|
|
163
|
+@@ -202,6 +204,7 @@ char *CONFIG_LOAD_MODULE_PATH = NULL;
|
|
164
|
+ char **CONFIG_LOAD_MODULE = NULL;
|
|
165
|
+
|
|
166
|
+ char *CONFIG_USER = NULL;
|
|
167
|
++int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
|
|
168
|
+
|
|
169
|
+ /* web monitoring */
|
|
170
|
+ #ifdef HAVE_LIBCURL
|
|
171
|
+@@ -666,6 +669,9 @@ int main(int argc, char **argv)
|
|
172
|
+ {
|
|
173
|
+ switch (ch)
|
|
174
|
+ {
|
|
175
|
++ case 'f':
|
|
176
|
++ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
|
|
177
|
++ break;
|
|
178
|
+ case 'c':
|
|
179
|
+ CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
|
|
180
|
+ break;
|
|
181
|
+@@ -705,7 +711,7 @@ int main(int argc, char **argv)
|
|
182
|
+ init_ipmi_handler();
|
|
183
|
+ #endif
|
|
184
|
+
|
|
185
|
+- return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
|
|
186
|
++ return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ int MAIN_ZABBIX_ENTRY()
|
|
190
|
+--- a/src/zabbix_server/server.c
|
|
191
|
++++ b/src/zabbix_server/server.c
|
|
192
|
+@@ -64,6 +64,7 @@ const char usage_message[] = "[-hV] [-c
|
|
193
|
+
|
|
194
|
+ const char *help_message[] = {
|
|
195
|
+ "Options:",
|
|
196
|
++ " -f --foreground Run in foreground don't fork",
|
|
197
|
+ " -c --config <file> Absolute path to the configuration file",
|
|
198
|
+ " -R --runtime-control <option> Perform administrative functions",
|
|
199
|
+ "",
|
|
200
|
+@@ -88,6 +89,7 @@ const char *help_message[] = {
|
|
201
|
+ /* long options */
|
|
202
|
+ static struct zbx_option longopts[] =
|
|
203
|
+ {
|
|
204
|
++ {"foreground", 0, NULL, 'f'},
|
|
205
|
+ {"config", 1, NULL, 'c'},
|
|
206
|
+ {"runtime-control", 1, NULL, 'R'},
|
|
207
|
+ {"help", 0, NULL, 'h'},
|
|
208
|
+@@ -96,7 +98,7 @@ static struct zbx_option longopts[] =
|
|
209
|
+ };
|
|
210
|
+
|
|
211
|
+ /* short options */
|
|
212
|
+-static char shortopts[] = "c:n:hVR:";
|
|
213
|
++static char shortopts[] = "c:n:fhVR:";
|
|
214
|
+
|
|
215
|
+ /* end of COMMAND LINE OPTIONS */
|
|
216
|
+
|
|
217
|
+@@ -197,6 +199,7 @@ char *CONFIG_LOAD_MODULE_PATH = NULL;
|
|
218
|
+ char **CONFIG_LOAD_MODULE = NULL;
|
|
219
|
+
|
|
220
|
+ char *CONFIG_USER = NULL;
|
|
221
|
++int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
|
|
222
|
+
|
|
223
|
+ /* web monitoring */
|
|
224
|
+ #ifdef HAVE_LIBCURL
|
|
225
|
+@@ -631,6 +634,9 @@ int main(int argc, char **argv)
|
|
226
|
+ {
|
|
227
|
+ switch (ch)
|
|
228
|
+ {
|
|
229
|
++ case 'f':
|
|
230
|
++ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
|
|
231
|
++ break;
|
|
232
|
+ case 'c':
|
|
233
|
+ CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
|
|
234
|
+ break;
|
|
235
|
+@@ -670,7 +676,7 @@ int main(int argc, char **argv)
|
|
236
|
+ init_ipmi_handler();
|
|
237
|
+ #endif
|
|
238
|
+
|
|
239
|
+- return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
|
|
240
|
++ return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ int MAIN_ZABBIX_ENTRY()
|