forked from million12/docker-zabbix-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeground.patch
More file actions
658 lines (567 loc) · 21.3 KB
/
foreground.patch
File metadata and controls
658 lines (567 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
Index: include/common.h
===================================================================
--- include/common.h (revision 56907)
+++ include/common.h (working copy)
@@ -70,6 +70,9 @@
#define ON 1
#define OFF 0
+#define ZBX_RUN_BACKGROUND 0
+#define ZBX_RUN_FOREGROUND 1
+
#if defined(_WINDOWS)
# define ZBX_SERVICE_NAME_LEN 64
extern char ZABBIX_SERVICE_NAME[ZBX_SERVICE_NAME_LEN];
Index: include/daemon.h
===================================================================
--- include/daemon.h (revision 56907)
+++ include/daemon.h (working copy)
@@ -28,7 +28,7 @@
#include "threads.h"
-int daemon_start(int allow_root, const char *user);
+int daemon_start(int allow_root, const char *user, int run_foreground);
void daemon_stop();
int zbx_sigusr_send(int flags);
@@ -36,6 +36,6 @@
#define ZBX_IS_RUNNING() 1
#define ZBX_DO_EXIT()
-#define START_MAIN_ZABBIX_ENTRY(a, u) daemon_start(a, u)
+#define START_MAIN_ZABBIX_ENTRY(a, u, f) daemon_start(a, u, f)
#endif /* ZABBIX_DAEMON_H */
Index: src/libs/zbxnix/daemon.c
===================================================================
--- src/libs/zbxnix/daemon.c (revision 56907)
+++ src/libs/zbxnix/daemon.c (working copy)
@@ -274,7 +274,8 @@
* *
* Parameters: allow_root - allow root permission for application *
* user - user on the system to which to drop the *
- * privileges *
+ * privileges
+ * run_foreground - allow running in foreground *
* *
* Author: Alexei Vladishev *
* *
@@ -281,7 +282,7 @@
* Comments: it doesn't allow running under 'root' if allow_root is zero *
* *
******************************************************************************/
-int daemon_start(int allow_root, const char *user)
+int daemon_start(int allow_root, const char *user, int run_foreground)
{
pid_t pid;
struct passwd *pwd;
@@ -336,15 +337,20 @@
#endif
}
- if (0 != (pid = zbx_fork()))
- exit(EXIT_SUCCESS);
+ if (ZBX_RUN_FOREGROUND != run_foreground)
+ if (0 != (pid = zbx_fork()))
+ exit(EXIT_SUCCESS);
setsid();
signal(SIGHUP, SIG_IGN);
- if (0 != (pid = zbx_fork()))
- exit(EXIT_SUCCESS);
+ if (ZBX_RUN_FOREGROUND == run_foreground) {
+ zabbix_log(LOG_LEVEL_INFORMATION, "Running in foreground");
+ } else {
+ if (0 != (pid = zbx_fork()))
+ exit(EXIT_SUCCESS);
+ }
if (-1 == chdir("/")) /* this is to eliminate warning: ignoring return value of chdir */
assert(0);
Index: src/libs/zbxsysinfo/linux/boottime.c
===================================================================
--- src/libs/zbxsysinfo/linux/boottime.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/boottime.c (working copy)
@@ -28,9 +28,9 @@
int ret = SYSINFO_RET_FAIL;
unsigned long value;
- if (NULL == (f = fopen("/proc/stat", "r")))
+ if (NULL == (f = fopen("/docker/proc/stat", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/stat: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/stat: %s", zbx_strerror(errno)));
return ret;
}
@@ -49,7 +49,7 @@
zbx_fclose(f);
if (SYSINFO_RET_FAIL == ret)
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"btime\" in /proc/stat."));
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"btime\" in /docker/proc/stat."));
return ret;
}
Index: src/libs/zbxsysinfo/linux/cpu.c
===================================================================
--- src/libs/zbxsysinfo/linux/cpu.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/cpu.c (working copy)
@@ -190,9 +190,9 @@
zbx_uint64_t value = 0;
FILE *f;
- if (NULL == (f = fopen("/proc/stat", "r")))
+ if (NULL == (f = fopen("/docker/proc/stat", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/stat: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/stat: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
@@ -211,7 +211,7 @@
zbx_fclose(f);
if (SYSINFO_RET_FAIL == ret)
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"ctxt\" in /proc/stat."));
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"ctxt\" in /docker/proc/stat."));
return ret;
}
@@ -223,9 +223,9 @@
zbx_uint64_t value = 0;
FILE *f;
- if (NULL == (f = fopen("/proc/stat", "r")))
+ if (NULL == (f = fopen("/docker/proc/stat", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/stat: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/stat: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
@@ -244,7 +244,7 @@
zbx_fclose(f);
if (SYSINFO_RET_FAIL == ret)
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"intr\" in /proc/stat."));
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot find a line with \"intr\" in /docker/proc/stat."));
return ret;
}
Index: src/libs/zbxsysinfo/linux/diskio.c
===================================================================
--- src/libs/zbxsysinfo/linux/diskio.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/diskio.c (working copy)
@@ -22,12 +22,12 @@
#include "stats.h"
#include "diskdevices.h"
-#define ZBX_DEV_PFX "/dev/"
+#define ZBX_DEV_PFX "/docker/dev/"
#define ZBX_DEV_READ 0
#define ZBX_DEV_WRITE 1
#if defined(KERNEL_2_4)
-# define INFO_FILE_NAME "/proc/partitions"
+# define INFO_FILE_NAME "/docker/proc/partitions"
# define PARSE(line) if (sscanf(line, ZBX_FS_UI64 ZBX_FS_UI64 " %*d %s " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d %*d %*d %*d", \
@@ -40,7 +40,7 @@
&ds[ZBX_DSTAT_W_SECT] \
) != 7) continue
#else
-# define INFO_FILE_NAME "/proc/diskstats"
+# define INFO_FILE_NAME "/docker/proc/diskstats"
# define PARSE(line) if (sscanf(line, ZBX_FS_UI64 ZBX_FS_UI64 " %s " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d " \
ZBX_FS_UI64 " %*d " ZBX_FS_UI64 " %*d %*d %*d %*d", \
Index: src/libs/zbxsysinfo/linux/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/linux/diskspace.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/diskspace.c (working copy)
@@ -118,9 +118,9 @@
FILE *f;
struct zbx_json j;
- if (NULL == (f = fopen("/proc/mounts", "r")))
+ if (NULL == (f = fopen("/docker/proc/mounts", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/mounts: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/mounts: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
Index: src/libs/zbxsysinfo/linux/hardware.h
===================================================================
--- src/libs/zbxsysinfo/linux/hardware.h (revision 56907)
+++ src/libs/zbxsysinfo/linux/hardware.h (working copy)
@@ -24,7 +24,7 @@
#define SMBIOS_STATUS_ERROR 2
#define SMBIOS_STATUS_OK 3
-#define DEV_MEM "/dev/mem"
+#define DEV_MEM "/docker/dev/mem"
#define SMBIOS_ENTRY_POINT_SIZE 0x20
#define DMI_HEADER_SIZE 4
@@ -36,9 +36,9 @@
#define DMI_GET_MODEL 0x04
#define DMI_GET_SERIAL 0x08
-#define CPU_MAX_FREQ_FILE "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq"
+#define CPU_MAX_FREQ_FILE "/docker/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq"
-#define HW_CPU_INFO_FILE "/proc/cpuinfo"
+#define HW_CPU_INFO_FILE "/docker/proc/cpuinfo"
#define HW_CPU_ALL_CPUS -1
#define HW_CPU_SHOW_ALL 1
#define HW_CPU_SHOW_MAXFREQ 2
Index: src/libs/zbxsysinfo/linux/kernel.c
===================================================================
--- src/libs/zbxsysinfo/linux/kernel.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/kernel.c (working copy)
@@ -43,9 +43,9 @@
{
zbx_uint64_t value;
- if (SYSINFO_RET_FAIL == read_uint64_from_procfs("/proc/sys/fs/file-max", &value))
+ if (SYSINFO_RET_FAIL == read_uint64_from_procfs("/docker/proc/sys/fs/file-max", &value))
{
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain data from /proc/sys/fs/file-max."));
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain data from /docker/proc/sys/fs/file-max."));
return SYSINFO_RET_FAIL;
}
@@ -57,9 +57,9 @@
{
zbx_uint64_t value;
- if (SYSINFO_RET_FAIL == read_uint64_from_procfs("/proc/sys/kernel/pid_max", &value))
+ if (SYSINFO_RET_FAIL == read_uint64_from_procfs("/docker/proc/sys/kernel/pid_max", &value))
{
- SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain data from /proc/sys/kernel/pid_max."));
+ SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain data from /docker/proc/sys/kernel/pid_max."));
return SYSINFO_RET_FAIL;
}
Index: src/libs/zbxsysinfo/linux/memory.c
===================================================================
--- src/libs/zbxsysinfo/linux/memory.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/memory.c (working copy)
@@ -72,9 +72,9 @@
char *t, c[MAX_STRING_LEN];
zbx_uint64_t res = 0;
- if (NULL == (f = fopen("/proc/meminfo", "r")))
+ if (NULL == (f = fopen("/docker/proc/meminfo", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/meminfo: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/meminfo: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
Index: src/libs/zbxsysinfo/linux/net.c
===================================================================
--- src/libs/zbxsysinfo/linux/net.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/net.c (working copy)
@@ -48,9 +48,9 @@
return SYSINFO_RET_FAIL;
}
- if (NULL == (f = fopen("/proc/net/dev", "r")))
+ if (NULL == (f = fopen("/docker/proc/net/dev", "r")))
{
- *error = zbx_dsprintf(NULL, "Cannot open /proc/net/dev: %s", zbx_strerror(errno));
+ *error = zbx_dsprintf(NULL, "Cannot open /docker/proc/net/dev: %s", zbx_strerror(errno));
return SYSINFO_RET_FAIL;
}
@@ -88,7 +88,7 @@
if (SYSINFO_RET_FAIL == ret)
{
- *error = zbx_strdup(NULL, "Cannot find information for this network interface in /proc/net/dev.");
+ *error = zbx_strdup(NULL, "Cannot find information for this network interface in /docker/proc/net/dev.");
return SYSINFO_RET_FAIL;
}
@@ -284,9 +284,9 @@
FILE *f;
struct zbx_json j;
- if (NULL == (f = fopen("/proc/net/dev", "r")))
+ if (NULL == (f = fopen("/docker/proc/net/dev", "r")))
{
- SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/net/dev: %s", zbx_strerror(errno)));
+ SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /docker/proc/net/dev: %s", zbx_strerror(errno)));
return SYSINFO_RET_FAIL;
}
@@ -344,7 +344,7 @@
buffer = zbx_malloc(NULL, buffer_alloc);
- if (0 < (n = proc_read_file("/proc/net/tcp", &buffer, &buffer_alloc)))
+ if (0 < (n = proc_read_file("/docker/proc/net/tcp", &buffer, &buffer_alloc)))
{
ret = SYSINFO_RET_OK;
@@ -359,7 +359,7 @@
}
}
- if (0 < (n = proc_read_file("/proc/net/tcp6", &buffer, &buffer_alloc)))
+ if (0 < (n = proc_read_file("/docker/proc/net/tcp6", &buffer, &buffer_alloc)))
{
ret = SYSINFO_RET_OK;
@@ -402,7 +402,7 @@
buffer = zbx_malloc(NULL, buffer_alloc);
- if (0 < (n = proc_read_file("/proc/net/udp", &buffer, &buffer_alloc)))
+ if (0 < (n = proc_read_file("/docker/proc/net/udp", &buffer, &buffer_alloc)))
{
ret = SYSINFO_RET_OK;
@@ -417,7 +417,7 @@
}
}
- if (0 < (n = proc_read_file("/proc/net/udp6", &buffer, &buffer_alloc)))
+ if (0 < (n = proc_read_file("/docker/proc/net/udp6", &buffer, &buffer_alloc)))
{
ret = SYSINFO_RET_OK;
Index: src/libs/zbxsysinfo/linux/proc.c
===================================================================
--- src/libs/zbxsysinfo/linux/proc.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/proc.c (working copy)
@@ -86,7 +86,7 @@
if (NULL == procname || '\0' == *procname)
return SUCCEED;
- /* process name in /proc/[pid]/status contains limited number of characters */
+ /* process name in /docker/proc/[pid]/status contains limited number of characters */
if (SUCCEED == cmp_status(f_stat, procname))
return SUCCEED;
@@ -266,12 +266,12 @@
if (0 == strcmp(entries->d_name, "self"))
continue;
- zbx_snprintf(tmp, sizeof(tmp), "/proc/%s/cmdline", entries->d_name);
+ zbx_snprintf(tmp, sizeof(tmp), "/docker/proc/%s/cmdline", entries->d_name);
if (NULL == (f_cmd = fopen(tmp, "r")))
continue;
- zbx_snprintf(tmp, sizeof(tmp), "/proc/%s/status", entries->d_name);
+ zbx_snprintf(tmp, sizeof(tmp), "/docker/proc/%s/status", entries->d_name);
if (NULL == (f_stat = fopen(tmp, "r")))
continue;
@@ -407,12 +407,12 @@
if (0 == strcmp(entries->d_name, "self"))
continue;
- zbx_snprintf(tmp, sizeof(tmp), "/proc/%s/cmdline", entries->d_name);
+ zbx_snprintf(tmp, sizeof(tmp), "/docker/proc/%s/cmdline", entries->d_name);
if (NULL == (f_cmd = fopen(tmp, "r")))
continue;
- zbx_snprintf(tmp, sizeof(tmp), "/proc/%s/status", entries->d_name);
+ zbx_snprintf(tmp, sizeof(tmp), "/docker/proc/%s/status", entries->d_name);
if (NULL == (f_stat = fopen(tmp, "r")))
continue;
Index: src/libs/zbxsysinfo/linux/sensors.c
===================================================================
--- src/libs/zbxsysinfo/linux/sensors.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/sensors.c (working copy)
@@ -21,9 +21,9 @@
#include "zbxregexp.h"
#if defined(KERNEL_2_4)
-#define DEVICE_DIR "/proc/sys/dev/sensors"
+#define DEVICE_DIR "/docker/proc/sys/dev/sensors"
#else
-#define DEVICE_DIR "/sys/class/hwmon"
+#define DEVICE_DIR "/docker/sys/class/hwmon"
static char *locations[] = {"", "/device", NULL};
#endif
@@ -180,7 +180,7 @@
}
else
{
- zbx_snprintf(bus_path, sizeof(bus_path), "/sys/class/i2c-adapter/i2c-%d", bus_i2c);
+ zbx_snprintf(bus_path, sizeof(bus_path), "/docker/sys/class/i2c-adapter/i2c-%d", bus_i2c);
bus_subfolder = sysfs_read_attr(bus_path, &bus_attr);
if (NULL != bus_subfolder && '\0' != *bus_subfolder)
Index: src/libs/zbxsysinfo/linux/software.h
===================================================================
--- src/libs/zbxsysinfo/linux/software.h (revision 56907)
+++ src/libs/zbxsysinfo/linux/software.h (working copy)
@@ -20,8 +20,8 @@
#ifndef ZABBIX_SOFTWARE_H
#define ZABBIX_SOFTWARE_H
-#define SW_OS_FULL "/proc/version"
-#define SW_OS_SHORT "/proc/version_signature"
+#define SW_OS_FULL "/docker/proc/version"
+#define SW_OS_SHORT "/docker/proc/version_signature"
#define SW_OS_NAME "/etc/issue.net"
typedef struct
Index: src/libs/zbxsysinfo/linux/swap.c
===================================================================
--- src/libs/zbxsysinfo/linux/swap.c (revision 56907)
+++ src/libs/zbxsysinfo/linux/swap.c (working copy)
@@ -78,7 +78,7 @@
swap_stat_t;
#ifdef KERNEL_2_4
-# define INFO_FILE_NAME "/proc/partitions"
+# define INFO_FILE_NAME "/docker/proc/partitions"
# define PARSE(line) \
\
if (6 != sscanf(line, "%d %d %*d %*s " \
@@ -92,7 +92,7 @@
&result->wsect /* wsect */ \
)) continue
#else
-# define INFO_FILE_NAME "/proc/diskstats"
+# define INFO_FILE_NAME "/docker/proc/diskstats"
# define PARSE(line) \
\
if (6 != sscanf(line, "%d %d %*s " \
@@ -158,9 +158,9 @@
FILE *f;
#ifdef KERNEL_2_4
- if (NULL != (f = fopen("/proc/stat", "r")))
+ if (NULL != (f = fopen("/docker/proc/stat", "r")))
#else
- if (NULL != (f = fopen("/proc/vmstat", "r")))
+ if (NULL != (f = fopen("/docker/proc/vmstat", "r")))
#endif
{
while (NULL != fgets(line, sizeof(line), f))
@@ -215,15 +215,15 @@
ret = get_swap_pages(result);
swapdev = NULL;
}
- else if (0 != strncmp(swapdev, "/dev/", 5))
+ else if (0 != strncmp(swapdev, "/docker/dev/", 5))
offset = 5;
- if (NULL == (f = fopen("/proc/swaps", "r")))
+ if (NULL == (f = fopen("/docker/proc/swaps", "r")))
return ret;
while (NULL != fgets(line, sizeof(line), f))
{
- if (0 != strncmp(line, "/dev/", 5))
+ if (0 != strncmp(line, "/docker/dev/", 5))
continue;
if (NULL == (s = strchr(line, ' ')))
Index: src/zabbix_agent/zabbix_agentd.c
===================================================================
--- src/zabbix_agent/zabbix_agentd.c (revision 56907)
+++ src/zabbix_agent/zabbix_agentd.c (working copy)
@@ -55,6 +55,8 @@
const char *progname = NULL;
+int CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+
/* default config file location */
#ifdef _WINDOWS
static char DEFAULT_CONFIG_FILE[] = "C:\\zabbix_agentd.conf";
@@ -82,9 +84,9 @@
/* application USAGE message */
const char usage_message[] =
#ifndef _WINDOWS
- "[-Vhp] [-R <runtime option>]"
+ "[-Vhfp] [-R <runtime option>]"
#else
- "[-Vhp] [-idsx] [-m]"
+ "[-Vhfp] [-idsx] [-m]"
#endif
" [-c <config-file>] [-t <item key>]";
/* end of application USAGE message */
@@ -93,6 +95,7 @@
const char *help_message[] = {
"Options:",
" -c --config <config-file> Absolute path to the configuration file",
+ " -f --foreground Run in foreground",
" -p --print Print known items and exit",
" -t --test <item key> Test specified item and exit",
" -h --help Display help information",
@@ -130,6 +133,7 @@
{"config", 1, NULL, 'c'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
+ {"foreground", 0, NULL, 'f'},
{"print", 0, NULL, 'p'},
{"test", 1, NULL, 't'},
#ifndef _WINDOWS
@@ -147,7 +151,7 @@
};
static char shortopts[] =
- "c:hVpt:"
+ "c:hVfpt:"
#ifndef _WINDOWS
"R:"
#else
@@ -263,6 +267,9 @@
#endif
exit(EXIT_SUCCESS);
break;
+ case 'f':
+ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+ break;
case 'p':
if (ZBX_TASK_START == t->task)
t->task = ZBX_TASK_PRINT_SUPPORTED;
@@ -944,7 +951,7 @@
break;
}
- START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER);
+ START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
exit(EXIT_SUCCESS);
}
Index: src/zabbix_proxy/proxy.c
===================================================================
--- src/zabbix_proxy/proxy.c (revision 56907)
+++ src/zabbix_proxy/proxy.c (working copy)
@@ -61,6 +61,7 @@
const char *help_message[] = {
"Options:",
" -c --config <file> Absolute path to the configuration file",
+ " -f --foreground Run in foreground",
" -R --runtime-control <option> Perform administrative functions",
"",
"Runtime control options:",
@@ -85,6 +86,7 @@
static struct zbx_option longopts[] =
{
{"config", 1, NULL, 'c'},
+ {"foreground", 0, NULL, 'f'},
{"runtime-control", 1, NULL, 'R'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
@@ -92,7 +94,7 @@
};
/* short options */
-static char shortopts[] = "c:hVR:";
+static char shortopts[] = "c:hVfR:";
/* end of COMMAND LINE OPTIONS */
@@ -197,6 +199,8 @@
/* zabbix server startup time */
int CONFIG_SERVER_STARTUP_TIME = 0;
+/* zabbix server
+int CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
char *CONFIG_LOAD_MODULE_PATH = NULL;
char **CONFIG_LOAD_MODULE = NULL;
@@ -669,6 +673,9 @@
case 'c':
CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
break;
+ case 'f':
+ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+ break;
case 'R':
if (SUCCEED != parse_rtc_options(zbx_optarg, daemon_type, &t.flags))
exit(EXIT_FAILURE);
@@ -705,7 +712,7 @@
init_ipmi_handler();
#endif
- return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
+ return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
}
int MAIN_ZABBIX_ENTRY()
Index: src/zabbix_server/server.c
===================================================================
--- src/zabbix_server/server.c (revision 56907)
+++ src/zabbix_server/server.c (working copy)
@@ -65,6 +65,7 @@
const char *help_message[] = {
"Options:",
" -c --config <file> Absolute path to the configuration file",
+ " -f --foreground Run in foreground",
" -R --runtime-control <option> Perform administrative functions",
"",
"Runtime control options:",
@@ -89,6 +90,7 @@
static struct zbx_option longopts[] =
{
{"config", 1, NULL, 'c'},
+ {"foreground", 0, NULL, 'f'},
{"runtime-control", 1, NULL, 'R'},
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 'V'},
@@ -96,7 +98,7 @@
};
/* short options */
-static char shortopts[] = "c:hVR:";
+static char shortopts[] = "c:hfVR:";
/* end of COMMAND LINE OPTIONS */
@@ -192,6 +194,7 @@
/* how often zabbix server sends configuration data to proxy, in seconds */
int CONFIG_PROXYCONFIG_FREQUENCY = 3600; /* 1h */
int CONFIG_PROXYDATA_FREQUENCY = 1; /* 1s */
+int CONFIG_FOREGROUND = ZBX_RUN_BACKGROUND;
char *CONFIG_LOAD_MODULE_PATH = NULL;
char **CONFIG_LOAD_MODULE = NULL;
@@ -634,6 +637,9 @@
case 'c':
CONFIG_FILE = zbx_strdup(CONFIG_FILE, zbx_optarg);
break;
+ case 'f':
+ CONFIG_FOREGROUND = ZBX_RUN_FOREGROUND;
+ break;
case 'R':
if (SUCCEED != parse_rtc_options(zbx_optarg, daemon_type, &t.flags))
exit(EXIT_FAILURE);
@@ -670,7 +676,7 @@
init_ipmi_handler();
#endif
- return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER);
+ return daemon_start(CONFIG_ALLOW_ROOT, CONFIG_USER, CONFIG_FOREGROUND);
}
int MAIN_ZABBIX_ENTRY()