Bug 81139 - UPDATE port: net-mgmt/nrpe2
Summary: UPDATE port: net-mgmt/nrpe2
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Pav Lucistnik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-16 23:50 UTC by Meno Abels
Modified: 2005-05-26 20:26 UTC (History)
1 user (show)

See Also:


Attachments
file.shar (7.83 KB, text/plain)
2005-05-16 23:50 UTC, Meno Abels
no flags Details
nrpe2.patch (4.22 KB, patch)
2005-05-25 10:22 UTC, Meno Abels
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Meno Abels 2005-05-16 23:50:01 UTC
	The nrpe2 does not write a pid file to /var/run. This does 
	not allow to run the standard rc.subr start/stop script.
	The current start/stop script has also some faults in the paths.
	So I added the writing of the pid to the source and changed
	the start/stop script to standard freebsd.
	I also deleted the following file:
		net-mgmt/nrpe2/pkg-plis
	And I added:
		net-mgmt/nrpe2/files/patch-pid-file
		net-mgmt/nrpe2/files/nrpe2.sh.in
	And I increased the PORTREVISION by one.
	So I think that a patch is more complex than a new shar. If you
	want to get a patch feel free to contact me. I also send the
	this change to Ethan Galstad (nagios@nagios.org) in the hope
	that i will accept this harmless extention.

How-To-Repeat: 	not applied change request
Comment 1 Pav Lucistnik freebsd_committer 2005-05-20 16:05:08 UTC
State Changed
From-To: open->feedback

Please resubmit as an unified diff between old and new port directory, like: 

diff -ruN /usr/ports/net-mgmt/nrpe2 ~/myports/nrpe2-modified 


Comment 2 Pav Lucistnik freebsd_committer 2005-05-20 16:05:08 UTC
Responsible Changed
From-To: freebsd-ports-bugs->pav

Track
Comment 3 Meno Abels 2005-05-25 05:00:24 UTC
Hello,

here is the unified diff, but think on my deleted and added files
which are not all mentioned in the diff.
Hopefully my mail client will not reformat the diff.

regards

meno

diff -ruN /usr/ports/net-mgmt/nrpe2/Makefile nrpe2.mod/Makefile
--- /usr/ports/net-mgmt/nrpe2/Makefile    Tue Dec 14 18:12:02 2004
+++ nrpe2.mod/Makefile    Tue May 17 00:36:08 2005
@@ -7,7 +7,7 @@
 
 PORTNAME=        nrpe2
 PORTVERSION=        2.0
-PORTREVISION=        0
+PORTREVISION=        1
 CATEGORIES=        net-mgmt
 MASTER_SITES=        ${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=    nagios
@@ -20,14 +20,17 @@
 
 GNU_CONFIGURE=        yes
 USE_PERL5_BUILD=    yes
+USE_REINPLACE=        yes
+
+USE_RC_SUBR=        nrpe2.sh
+SUB_FILES=          nrpe2.sh
+
+PLIST_FILES=           sbin/nrpe2 etc/nrpe.cfg-sample 
libexec/nagios/check_nrpe2
 
 CONFIGURE_ARGS+=    --libexecdir=${PREFIX}/libexec/nagios 
--bindir=${PREFIX}/sbin --sysconfdir=${PREFIX}/etc
 
 OPTIONS=        SSL "SSL support" off \
             ARGS "Enable command arguments *POTENTIAL SECURITY RISK*" off
-
-.include <bsd.port.pre.mk>
-
 .if defined(WITH_SSL)
 USE_OPENSSL=    yes
 CONFIGURE_ARGS+=    --enable-ssl
@@ -43,6 +46,5 @@
     ${INSTALL_PROGRAM} ${WRKSRC}/src/nrpe ${PREFIX}/sbin/nrpe2
     ${INSTALL_PROGRAM} ${WRKSRC}/src/check_nrpe 
${PREFIX}/libexec/nagios/check_nrpe2
     ${INSTALL_DATA} ${WRKSRC}/nrpe.cfg ${PREFIX}/etc/nrpe.cfg-sample
-    ${INSTALL_SCRIPT} ${WRKSRC}/init-script.freebsd 
${PREFIX}/etc/rc.d/nrpe.sh
 
-.include <bsd.port.post.mk>
+.include <bsd.port.mk>
diff -ruN /usr/ports/net-mgmt/nrpe2/files/nrpe2.sh.in 
nrpe2.mod/files/nrpe2.sh.in
--- /usr/ports/net-mgmt/nrpe2/files/nrpe2.sh.in    Thu Jan  1 01:00:00 1970
+++ nrpe2.mod/files/nrpe2.sh.in    Tue May 17 00:09:40 2005
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: nrpe2
+# REQUIRE: NETWORKING
+# KEYWORD: FreeBSD shutdown
+
+#
+# Add the following lines to /etc/rc.conf to enable nrpe2:
+#
+#nrpe2_enable="YES"
+#
+#
+
+. %%RC_SUBR%%
+
+name=nrpe2
+rcvar=`set_rcvar`
+
+command="%%PREFIX%%/sbin/nrpe2"
+required_files=%%PREFIX%%/etc/nrpe.cfg
+command_args="-c ${required_files} -d"
+pidfile=/var/run/${name}.pid
+
+# set defaults
+
+nrpe2_enable=${nrpe2_enable:-"NO"}
+nrpe2_flags=${nrpe2_flags:-""}
+
+load_rc_config ${name}
+run_rc_command "$1"
diff -ruN /usr/ports/net-mgmt/nrpe2/files/patch-pid-file 
nrpe2.mod/files/patch-pid-file
--- /usr/ports/net-mgmt/nrpe2/files/patch-pid-file    Thu Jan  1 
01:00:00 1970
+++ nrpe2.mod/files/patch-pid-file    Tue May 17 00:34:04 2005
@@ -0,0 +1,76 @@
+--- orig/nrpe-2.0/src/Makefile.in    Tue Aug  5 07:01:53 2003
++++ src/Makefile.in    Tue May 17 00:25:33 2005
+@@ -9,7 +9,7 @@
+ SRC_COMMON=../common
+
+ CC=@CC@
+-CFLAGS=@CFLAGS@ @DEFS@
++CFLAGS=@CFLAGS@ @DEFS@ -DPID_DIR=\"/var/run/\"
+ LDFLAGS=@LDFLAGS@ @LIBS@
+ SOCKETLIBS=@SOCKETLIBS@
+
+--- orig/nrpe-2.0/src/nrpe.c    Tue Sep  9 04:52:37 2003
++++ src/nrpe.c    Tue May 17 00:24:29 2005
+@@ -23,6 +23,7 @@
+ #include "nrpe.h"
+ #include "utils.h"
+
++
+ #ifdef HAVE_SSL
+ #include "dh.h"
+ #endif
+@@ -83,7 +84,6 @@
+ #endif
+
+
+-
+ int main(int argc, char **argv){
+     int result=OK;
+     int x;
+@@ -219,7 +219,45 @@
+
+     /* else daemonize and start listening for requests... */
+     else if(fork()==0){
+-
++#ifdef PID_DIR
++        int fd;
++        int pid_written = 0;
++        char *pid_fname;
++        char pbuf[16];
++        char *bname = strrchr(argv[0], '/'); /* basename from XPG4.2 
would be nice */
++
++        bname = !bname ? argv[0] : ++bname;
++        pid_fname = malloc(strlen(PID_DIR) + strlen(bname) + 
sizeof(".pid"));
++        strcpy(pid_fname, PID_DIR);
++        strcat(pid_fname, bname); strcat(pid_fname, ".pid");
++        if ((fd = open (pid_fname, O_RDONLY)) >= 0) {
++            int status = read (fd, pbuf, (sizeof pbuf) - 1);
++            close (fd);
++            if (status > 0) {
++                int pid;
++                pbuf [status] = 0;
++                pid = atoi (pbuf);
++                /* If the previous server process is not still running,
++                   write a new pid file immediately. */
++                if (pid && (pid == getpid() || kill (pid, 0) < 0)) {
++                    unlink (pid_fname);
++                } else {
++                    syslog(LOG_ERR,"There's already a nrpe server 
running.");
++                    free(pid_fname);
++                    return STATE_CRITICAL;
++                }
++            }
++        }
++        if ((fd = open (pid_fname, O_WRONLY | O_CREAT, 0644)) >= 0) {
++            sprintf (pbuf, "%d\n", (int)getpid ());
++            write (fd, pbuf, strlen (pbuf));
++            close (fd);
++        } else {
++            syslog(LOG_ERR,"Can not write the pidfile(%s).", pid_fname);
++        }
++        free(pid_fname);
++#endif
++       
+         /* we're a daemon - set up a new process group */
+         setsid();
+
Comment 4 Pav Lucistnik freebsd_committer 2005-05-25 08:38:12 UTC
Diff got corrupted by your mailer (tabs->spaces, lines got wrapped),
perhaps you could upload the diff on webspace somewhere?

Oh and you made one mistake in it, you removed
.include <bsd.port.pre.mk> which is mandatory when using OPTIONS
(OPTIONS definition must be above it, WITH_* WITHOUT_* variables can be
used only below it).

-- 
Pav Lucistnik <pav@oook.cz>
              <pav@FreeBSD.org>

The number you dialed is imaginary.
Please turn your phone by 90 degrees and try again.
Comment 5 Meno Abels 2005-05-25 10:22:00 UTC
Hello,

i fixed the makefile as you recommended. The quirk was there before a 
started to work on.
I attach now the diff so it will be ok-:)

regards

Meno

>Diff got corrupted by your mailer (tabs->spaces, lines got wrapped),
>perhaps you could upload the diff on webspace somewhere?
>
>Oh and you made one mistake in it, you removed
>.include <bsd.port.pre.mk> which is mandatory when using OPTIONS
>(OPTIONS definition must be above it, WITH_* WITHOUT_* variables can be
>used only below it).
>
>  
>
Comment 6 Pav Lucistnik freebsd_committer 2005-05-25 10:25:36 UTC
Meno Abels p=ED=B9e v st 25. 05. 2005 v 11:22 +0200:

> i fixed the makefile as you recommended. The quirk was there before a=20
> started to work on.
> I attach now the diff so it will be ok-:)

Patch to Makefile does not apply... you're diffing it against unmodified
Makefile as in ports now, right?

--=20
Pav Lucistnik <pav@oook.cz>
              <pav@FreeBSD.org>

A spoonful of curry, garlic and mustard helps the medicine go down...
and come straight back up again.
  -- JLE on #angband
Comment 7 Pav Lucistnik freebsd_committer 2005-05-26 18:29:34 UTC
Dear maintainer of FreeBSD port net-mgmt/nrpe2, please take a look at
the following patch, which 

- adds rcng startup script
- make nrpe write pid file in /var/run
- replaces pkg-plist file with PLIST_FILES in Makefile

Do you approve this patch?


Index: Makefile
===================================================================
RCS file: /home/pcvs/ports/net-mgmt/nrpe2/Makefile,v
retrieving revision 1.14
diff -a -u -r1.14 Makefile
--- Makefile	14 Dec 2004 17:12:02 -0000	1.14
+++ Makefile	26 May 2005 17:25:36 -0000
@@ -7,7 +7,7 @@
 
 PORTNAME=		nrpe2
 PORTVERSION=		2.0
-PORTREVISION=		0
+PORTREVISION=		1
 CATEGORIES=		net-mgmt
 MASTER_SITES=		${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=	nagios
@@ -20,6 +20,11 @@
 
 GNU_CONFIGURE=		yes
 USE_PERL5_BUILD=	yes
+USE_REINPLACE=		yes
+
+USE_RC_SUBR=		nrpe2.sh
+
+PLIST_FILES=		sbin/nrpe2 etc/nrpe.cfg-sample libexec/nagios/check_nrpe2
 
 CONFIGURE_ARGS+=	--libexecdir=${PREFIX}/libexec/nagios --bindir=${PREFIX}/sbin --sysconfdir=${PREFIX}/etc
 
@@ -43,6 +48,5 @@
 	${INSTALL_PROGRAM} ${WRKSRC}/src/nrpe ${PREFIX}/sbin/nrpe2
 	${INSTALL_PROGRAM} ${WRKSRC}/src/check_nrpe ${PREFIX}/libexec/nagios/check_nrpe2
 	${INSTALL_DATA} ${WRKSRC}/nrpe.cfg ${PREFIX}/etc/nrpe.cfg-sample
-	${INSTALL_SCRIPT} ${WRKSRC}/init-script.freebsd ${PREFIX}/etc/rc.d/nrpe.sh
 
 .include <bsd.port.post.mk>
Index: pkg-plist
===================================================================
RCS file: pkg-plist
diff -N pkg-plist
--- pkg-plist	28 Aug 2004 17:56:17 -0000	1.4
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,4 +0,0 @@
-sbin/nrpe2
-etc/nrpe.cfg-sample
-etc/rc.d/nrpe.sh
-libexec/nagios/check_nrpe2
Index: files/nrpe2.sh.in
===================================================================
RCS file: files/nrpe2.sh.in
diff -N files/nrpe2.sh.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ files/nrpe2.sh.in	26 May 2005 17:25:36 -0000
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: nrpe2
+# REQUIRE: NETWORKING
+# KEYWORD: FreeBSD shutdown
+
+#
+# Add the following lines to /etc/rc.conf to enable nrpe2:
+#
+#nrpe2_enable="YES"
+#
+#
+
+. %%RC_SUBR%%
+
+name=nrpe2
+rcvar=`set_rcvar`
+
+command="%%PREFIX%%/sbin/nrpe2"
+required_files=%%PREFIX%%/etc/nrpe.cfg
+command_args="-c ${required_files} -d"
+pidfile=/var/run/${name}.pid
+
+# set defaults
+
+nrpe2_enable=${nrpe2_enable:-"NO"}
+nrpe2_flags=${nrpe2_flags:-""}
+
+load_rc_config ${name}
+run_rc_command "$1"
Index: files/patch-pid-file
===================================================================
RCS file: files/patch-pid-file
diff -N files/patch-pid-file
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ files/patch-pid-file	26 May 2005 17:25:36 -0000
@@ -0,0 +1,76 @@
+--- orig/nrpe-2.0/src/Makefile.in	Tue Aug  5 07:01:53 2003
++++ src/Makefile.in	Tue May 17 00:25:33 2005
+@@ -9,7 +9,7 @@
+ SRC_COMMON=../common
+ 
+ CC=@CC@
+-CFLAGS=@CFLAGS@ @DEFS@
++CFLAGS=@CFLAGS@ @DEFS@ -DPID_DIR=\"/var/run/\" 
+ LDFLAGS=@LDFLAGS@ @LIBS@
+ SOCKETLIBS=@SOCKETLIBS@
+ 
+--- orig/nrpe-2.0/src/nrpe.c	Tue Sep  9 04:52:37 2003
++++ src/nrpe.c	Tue May 17 00:24:29 2005
+@@ -23,6 +23,7 @@
+ #include "nrpe.h"
+ #include "utils.h"
+ 
++
+ #ifdef HAVE_SSL
+ #include "dh.h"
+ #endif
+@@ -83,7 +84,6 @@
+ #endif
+ 
+ 
+-
+ int main(int argc, char **argv){
+ 	int result=OK;
+ 	int x;
+@@ -219,7 +219,45 @@
+ 
+ 	/* else daemonize and start listening for requests... */
+ 	else if(fork()==0){
+-
++#ifdef PID_DIR
++		int fd;
++		int pid_written = 0;
++		char *pid_fname;
++		char pbuf[16];
++		char *bname = strrchr(argv[0], '/'); /* basename from XPG4.2 would be nice */
++
++		bname = !bname ? argv[0] : ++bname;
++		pid_fname = malloc(strlen(PID_DIR) + strlen(bname) + sizeof(".pid"));
++		strcpy(pid_fname, PID_DIR);
++		strcat(pid_fname, bname); strcat(pid_fname, ".pid");
++		if ((fd = open (pid_fname, O_RDONLY)) >= 0) {
++			int status = read (fd, pbuf, (sizeof pbuf) - 1);
++			close (fd);
++			if (status > 0) {
++				int pid;
++				pbuf [status] = 0;
++				pid = atoi (pbuf);
++				/* If the previous server process is not still running,
++				   write a new pid file immediately. */
++				if (pid && (pid == getpid() || kill (pid, 0) < 0)) {
++					unlink (pid_fname);
++				} else {
++					syslog(LOG_ERR,"There's already a nrpe server running.");
++					free(pid_fname);
++					return STATE_CRITICAL;
++				}
++			}
++		} 
++		if ((fd = open (pid_fname, O_WRONLY | O_CREAT, 0644)) >= 0) {
++			sprintf (pbuf, "%d\n", (int)getpid ());
++			write (fd, pbuf, strlen (pbuf));
++			close (fd);
++		} else {
++			syslog(LOG_ERR,"Can not write the pidfile(%s).", pid_fname);
++		}
++		free(pid_fname);
++#endif
++		
+ 		/* we're a daemon - set up a new process group */
+ 		setsid();
+ 

-- 
Pav Lucistnik <pav@oook.cz>
              <pav@FreeBSD.org>

Oh, no! Aaargh! It is the most unnatural, most disgusting
creature imaginable: a two-eyed cyclops!
Comment 8 Paul Dlug 2005-05-26 20:08:57 UTC
On May 26, 2005, at 1:29 PM, Pav Lucistnik wrote:

> Dear maintainer of FreeBSD port net-mgmt/nrpe2, please take a look at
> the following patch, which
>
> - adds rcng startup script
> - make nrpe write pid file in /var/run
> - replaces pkg-plist file with PLIST_FILES in Makefile
>
> Do you approve this patch?

This looks good to me, thanks.


--Paul
Comment 9 Pav Lucistnik freebsd_committer 2005-05-26 20:26:13 UTC
State Changed
From-To: feedback->closed

Committed, thanks!