Page 1 of 1

[Nagios-devel] NRPE patch: 'stay in foreground' option

Posted: Sat Oct 18, 2003 9:52 pm
by Guest
--Boundary-00=_iKak/58Q1sZLI2X
Content-Type: text/plain;
charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello people,

A friend of mine has recently had a bit of a problem with NRPE, where he
needed it to stay in the foreground rather than fork (for the details,
he needs to run it through some Daemontools wrapper on a machine where
he doesn't have root access). I figured the easiest way was to write a
li'l patch for NRPE itself, which is what I did. Since another friend
suggested the Nifty Developper Team might actually be interested in it,
well, here it is for you to peek and poke at.

The patch was made against the nightly CVS tarball and adds a new option
to NRPE, -f/--foreground.

When used in --daemon mode, this option causes NRPE to not fork, and to
remain attached to the running process (shell, Daemontools utility,
etc).

When used in --inetd mode it won't do anything.

There. I did Something Potentially Useful today, yay!

-- Pascal 'Sundance' Varet

PS: I'm sending it to this list as per the FAQ's instructions -- though
I'm not sure whether it qualifies for an 'extra' such as NRPE (or does
it count as a plug-in...?). If not, please accept my apologies, and
feel free to print out this message and play darts on it. Thanks. :)

--Boundary-00=_iKak/58Q1sZLI2X
Content-Type: text/x-diff;
charset="iso-8859-15";
name="nrpe-foreground.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="nrpe-foreground.patch"

--- nrpe.c.old 2003-10-18 21:26:28.000000000 +0200
+++ nrpe.c 2003-10-18 21:43:08.000000000 +0200
@@ -77,6 +77,7 @@
int show_version=FALSE;
int use_inetd=TRUE;
int debug=FALSE;
+int stay_in_foreground=FALSE;

#ifdef HAVE_SSL
SSL_METHOD *meth;
@@ -231,6 +232,19 @@
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();
+
+ /* wait for connections */
+ wait_for_connections();
+ }
+
/* else daemonize and start listening for requests... */
else if(fork()==0){

@@ -1447,6 +1461,7 @@
static struct option long_options[]={
{"config", required_argument, 0, 'c'},
{"inetd", no_argument, 0, 'i'},
+ {"foreground", no_argument, 0, 'f'},
{"daemon", no_argument, 0, 'd'},
{"no-ssl", no_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
@@ -1459,7 +1474,7 @@
if(argc<2)
return ERROR;

- snprintf(optchars,MAX_INPUT_BUFFER,"c:nidhl");
+ snprintf(optchars,MAX_INPUT_BUFFER,"c:nidhlf");

while(1){
#ifdef HAVE_GETOPT_H
@@ -1495,6 +1510,9 @@
use_inetd=TRUE;
have_mode=TRUE;
break;
+ case 'f':
+ stay_in_foreground=TRUE;
+ break;
case 'n':
use_ssl=FALSE;
break;

--Boundary-00=_iKak/58Q1sZLI2X--






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]