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
|
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Mon, 28 Aug 2017 21:13:00 +0200
Subject: [PATCH] Add option "stay in foreground"
This patch is based on https://support.nagios.com/forum/viewtopic.php?f=34&t=17597.
--- a/src/nrpe.c
+++ b/src/nrpe.c
@@ -98,6 +98,7 @@
int use_inetd=TRUE;
int debug=FALSE;
int use_src=FALSE; /* Define parameter for SRC option */
+int stay_in_foreground=FALSE;
void complete_SSL_shutdown( SSL *);
@@ -171,6 +172,7 @@
printf(" -d = Run as a standalone daemon\n");
/* Updates help section to indicate how to start under SRC on AIX */
printf(" -d -s = Run as a subsystem under AIX\n");
+ printf(" -f = Run and stay in foreground\n");
printf("\n");
printf("Notes:\n");
printf("This program is designed to process requests from the check_nrpe\n");
@@ -292,6 +294,22 @@
handle_connection(0);
}
+ /* if we're running in the foreground... */
+ else if (stay_in_foreground==TRUE){
+
+ /* drop privileges */
+ drop_privileges(nrpe_user,nrpe_group);
+
+ /* make sure we're not root */
+ check_privileges();
+
+ /* log info to syslog facility */
+ syslog(LOG_NOTICE,"Starting up NRPE");
+
+ /* wait for connections */
+ wait_for_connections();
+ }
+
/* if we're running under SRC...
we don't fork but does drop-privileges*/
else if (use_src==TRUE){
@@ -2088,6 +2103,7 @@
{"4", no_argument, 0, '4'},
{"6", no_argument, 0, '4'},
{"daemon", no_argument, 0, 'd'},
+ {"foreground", no_argument, 0, 'f'},
{"no-ssl", no_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
{"license", no_argument, 0, 'l'},
@@ -2099,7 +2115,7 @@
if(argc<2)
return ERROR;
- snprintf(optchars,MAX_INPUT_BUFFER,"c:hVldi46n");
+ snprintf(optchars,MAX_INPUT_BUFFER,"c:hVldi46nf");
while(1){
#ifdef HAVE_GETOPT_LONG
@@ -2130,6 +2146,11 @@
case 'd':
use_inetd=FALSE;
have_mode=TRUE;
+ break;
+ case 'f':
+ stay_in_foreground=TRUE;
+ use_inetd=FALSE;
+ have_mode=TRUE;
break;
case 'i':
use_inetd=TRUE;
|