Bug 68787 - [MAINTAINER] net-mgmt/arpwatch-devel: RC_SUBR-ize
Summary: [MAINTAINER] net-mgmt/arpwatch-devel: RC_SUBR-ize
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: Kirill Ponomarev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-07 22:40 UTC by Matthew George
Modified: 2004-07-09 17:50 UTC (History)
0 users

See Also:


Attachments
file.diff (461 bytes, patch)
2004-07-07 22:40 UTC, Matthew George
no flags Details | Diff
file.diff (614 bytes, patch)
2004-07-07 22:40 UTC, Matthew George
no flags Details | Diff
file.diff (520 bytes, patch)
2004-07-07 22:40 UTC, Matthew George
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew George 2004-07-07 22:40:21 UTC
	add support for rc_subr mechanism.  this includes a change to
properly daemon()ize arpwatch.

Fix: # This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	pkg-message
#
echo x - pkg-message
sed 's/^X//' >pkg-message << 'END-of-pkg-message'
X
X*** ATTENTION ***
X
XTo run arpwatch from startup, add
Xarpwatch_enable="YES" to /etc/rc.conf
X
XAvailable variables you add/set to /etc/rc.conf.
X- arpwatch_enable (bool):      Set to "NO" by default.
X                               Set it to "YES" to enable arpwatch.
X- arpwatch_flags (str):        Set to "-N" by default.
X                               Extra flags passed to start command.
X
END-of-pkg-message
exit

PORTNAME=	arpwatch
 PORTVERSION=	2.1.a11
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	net-mgmt
 MASTER_SITES=	http://www.Awfulhak.org/arpwatch/ \
 		ftp://ftp.ee.lbl.gov/
@@ -25,8 +25,15 @@
 INSTALL_TARGET=	install install-man
 MAN8=		arpwatch.8 arpsnmp.8

+USE_RC_SUBR=	yes
+RC_SCRIPTS_SUB=	PREFIX=${PREFIX} RC_SUBR=${RC_SUBR}
+
 MAKE_ENV=	PTHREAD_CFLAGS="${PTHREAD_CFLAGS}" PTHREAD_LIBS="${PTHREAD_LIBS}"

+post-patch:
+	@${SED} ${RC_SCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
+		${FILESDIR}/arpwatch.sh > ${WRKDIR}/arpwatch.sh
+
 post-install:
 	if [ ! -d ${PREFIX}/arpwatch ]; then				\
 		${MKDIR} ${PREFIX}/arpwatch;				\
@@ -41,6 +48,7 @@
 		${INSTALL_DATA} ${WRKSRC}/$$file ${PREFIX}/arpwatch/.;	\
 	done
 	${INSTALL_SCRIPT} ${WRKSRC}/arp2ethers ${PREFIX}/arpwatch/.
-	${INSTALL_SCRIPT} ${FILESDIR}/arpwatch.sh ${PREFIX}/etc/rc.d/arpwatch.sh.sample
+	${INSTALL_SCRIPT} ${WRKDIR}/arpwatch.sh ${PREFIX}/etc/rc.d/arpwatch.sh
+	@${CAT} ${PKGMESSAGE}

 .include <bsd.port.mk>


-if [ -r /etc/defaults/rc.conf ]; then
-	. /etc/defaults/rc.conf
-	source_rc_confs
-elif [ -r /etc/rc.conf ]; then
-	. /etc/rc.conf
-fi
-
-prog=$(realpath $0) || exit 1
-dir=${prog%/*}
-PREFIX=${dir%/etc/rc.d}
-
-if [ ."$dir" = ."$prog" -o ."$PREFIX" = ."$dir" ]
-then
-	echo "$0: Cannot determine the PREFIX" >&2
-	exit 1
-fi
-
-case $1 in
-start)
-	if [ ! -e "$PREFIX"/arpwatch/arp.dat ]; then
-		if [ -e "$PREFIX"/arpwatch/arp.dat- ]; then
-			cp "$PREFIX"/arpwatch/arp.dat- "$PREFIX"/arpwatch/arp.dat
-		else
-			touch "$PREFIX"/arpwatch/arp.dat
-		fi
-	fi
-
-	if [ ! -e "$PREFIX"/arpwatch/ether.dat ]; then
-		if [ -e "$PREFIX"/arpwatch/ether.dat- ]; then
-			cp "$PREFIX"/arpwatch/ether.dat- "$PREFIX"/arpwatch/ether.dat
-		else
-			touch "$PREFIX"/arpwatch/ether.dat
-		fi
-	fi
-
-	case ${arpwatch_interfaces} in
-	'')
-		if [ -x "$PREFIX"/sbin/arpwatch -a -d "$PREFIX"/arpwatch ]; then
-			"$PREFIX"/sbin/arpwatch ${arpwatch_flags} && echo -n ' arpwatch'
-		fi
-		;;
-	*)
-		for interface in ${arpwatch_interfaces}; do
-			"$PREFIX"/sbin/arpwatch -i "${interface}" && echo -n " arpwatch(${interface})"
-		done
-		;;
-	esac
-	;;
-stop)
-	killall arpwatch && echo -n ' arpwatch'
-	;;
-*)
-	echo "Usage: `basename $0` {start|stop}" >&2
-	exit 64
-	;;
-esac
+command="%%PREFIX%%/sbin/arpwatch"
+
+[ -z "$arpwatch_enable" ]       && arpwatch_enable="NO"
+[ -z "$arpwatch_flags" ]        && arpwatch_flags="-N"
+
+load_rc_config $name
+
+run_rc_command "$1"

-exit 0




/* Drop into the background if not debugging */
-@@ -238,7 +259,7 @@
- 				exit(0);
- 			(void)close(fileno(stdin));
- 			(void)close(fileno(stdout));
+ 		if (!debug) {
+-			pid = fork();
+-			if (pid < 0) {
+-				syslog(LOG_ERR, "main fork(): %m");
+-				exit(1);
+-			} else if (pid != 0)
+-				exit(0);
+-			(void)close(fileno(stdin));
+-			(void)close(fileno(stdout));
 -			(void)close(fileno(stderr));
-+
- #ifdef TIOCNOTTY
- 			fd = open("/dev/tty", O_RDWR);
- 			if (fd >= 0) {
-@@ -251,12 +272,82 @@
+-#ifdef TIOCNOTTY
+-			fd = open("/dev/tty", O_RDWR);
+-			if (fd >= 0) {
+-				(void)ioctl(fd, TIOCNOTTY, 0);
+-				(void)close(fd);
+-			}
+-#else
+-			(void) setsid();
+-#endif
++			daemon(1, 0);
  		}
  	}

@@ -214,7 +224,7 @@

  	if (rfilename != NULL) {
  		pd = pcap_open_offline(rfilename, errbuf);
-@@ -306,27 +397,7 @@
+@@ -306,27 +380,7 @@
  	if (rfilename == NULL)
  		syslog(LOG_INFO, "listening on %s", interface);

@@ -242,7 +252,7 @@

  	switch (linktype) {

-@@ -347,9 +418,7 @@
+@@ -347,9 +401,7 @@
  		exit(1);
  	}
  	pcap_close(pd);
@@ -253,7 +263,7 @@
  }

  /* Process an ethernet arp/rarp packet */
-@@ -362,6 +431,8 @@
+@@ -362,6 +414,8 @@
  	register u_char *sea, *sha;
  	register time_t t;
  	u_int32_t sia;
@@ -262,7 +272,7 @@

  	eh = (struct ether_header *)p;
  	ea = (struct ether_arp *)(eh + 1);
-@@ -400,9 +471,16 @@
+@@ -400,9 +454,16 @@
  	/* Got a live one */
  	t = h->ts.tv_sec;
  	can_checkpoint = 0;
@@ -280,7 +290,7 @@
  	can_checkpoint = 1;
  }

-@@ -507,6 +585,8 @@
+@@ -507,6 +568,8 @@
  	register u_char *sea, *sha;
  	register time_t t;
  	u_int32_t sia;
@@ -289,7 +299,7 @@

  	fh = (struct fddi_header *)p;
  	ea = (struct ether_arp *)(fh + 1);
-@@ -549,7 +629,13 @@
+@@ -549,7 +612,13 @@
  	/* Got a live one */
  	t = h->ts.tv_sec;
  	can_checkpoint = 0;
@@ -304,7 +314,7 @@
  		syslog(LOG_ERR, "ent_add(%s, %s, %ld) failed",
  		    intoa(sia), e2str(sea), t);
  	can_checkpoint = 1;
-@@ -750,7 +836,7 @@
+@@ -750,7 +819,7 @@
  	extern char version[];

  	(void)fprintf(stderr, "Version %s\n", version);


-- 
Matthew George
SecureWorks Technical Operations--MZMIpZKAyFEFpjyOa7BB2iE4lpOviBPMmiDei42T8CZ9RASZ
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

--- Makefile.orig	Wed Jul  7 17:31:28 2004
+++ Makefile	Wed Jul  7 17:32:36 2004
@@ -2,12 +2,12 @@
 # Date created:         11 November 2003
 # Whom:                 Matthew George <mdg@secureworks.net>
 #
-# $FreeBSD: ports/net-mgmt/arpwatch-devel/Makefile,v 1.36 2004/06/11 18:30:10 krion Exp $
+# $FreeBSD: ports/net-mgmt/arpwatch-devel/Makefile,v 1.35 2004/04/14 21:30:24 krion Exp $
 #
Comment 1 Kirill Ponomarev freebsd_committer freebsd_triage 2004-07-07 22:41:14 UTC
Responsible Changed
From-To: freebsd-ports-bugs->krion

Grab.
Comment 2 Kirill Ponomarev freebsd_committer freebsd_triage 2004-07-09 17:50:06 UTC
State Changed
From-To: open->closed

Committed, thanks!