From b7e46f91755aa93b435b847274312fd87af6f4f7 Mon Sep 17 00:00:00 2001 From: mrg Date: Thu, 23 Apr 1998 02:48:33 +0000 Subject: [PATCH] support /var/run/rarpd.pid --- usr.sbin/rarpd/pathnames.h | 31 +++++++++++++++++++++++++++++++ usr.sbin/rarpd/rarpd.c | 20 +++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 usr.sbin/rarpd/pathnames.h diff --git a/usr.sbin/rarpd/pathnames.h b/usr.sbin/rarpd/pathnames.h new file mode 100644 index 000000000000..1f3e93a3c3c5 --- /dev/null +++ b/usr.sbin/rarpd/pathnames.h @@ -0,0 +1,31 @@ +/* $NetBSD: pathnames.h,v 1.1 1998/04/23 02:48:33 mrg Exp $ */ + +/* + * Copyright (c) 1998 Matthew R. Green + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + #define _PATH_RARPDPID "/var/run/rarpd.pid" diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c index 641e61d82f3b..0d40876dae9c 100644 --- a/usr.sbin/rarpd/rarpd.c +++ b/usr.sbin/rarpd/rarpd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rarpd.c,v 1.24 1998/04/15 15:06:06 mrg Exp $ */ +/* $NetBSD: rarpd.c,v 1.25 1998/04/23 02:48:33 mrg Exp $ */ /* * Copyright (c) 1990 The Regents of the University of California. @@ -28,7 +28,7 @@ __COPYRIGHT( #endif /* not lint */ #ifndef lint -__RCSID("$NetBSD: rarpd.c,v 1.24 1998/04/15 15:06:06 mrg Exp $"); +__RCSID("$NetBSD: rarpd.c,v 1.25 1998/04/23 02:48:33 mrg Exp $"); #endif @@ -70,6 +70,8 @@ __RCSID("$NetBSD: rarpd.c,v 1.24 1998/04/15 15:06:06 mrg Exp $"); #include #include +#include "pathnames.h" + #define FATAL 1 /* fatal error occurred */ #define NONFATAL 0 /* non fatal error occurred */ @@ -172,6 +174,8 @@ main(argc, argv) init_one(ifname); if ((!fflag) && (!dflag)) { + FILE *fp; + pid = fork(); if (pid > 0) /* Parent exits, leaving child in background. */ @@ -181,6 +185,13 @@ main(argc, argv) rarperr(FATAL, "cannot fork"); /* NOTREACHED */ } + + /* write pid file */ + if ((fp = fopen(_PATH_RARPDPID, "w")) != NULL) { + fprintf(fp, "%u\n", getpid()); + (void)fclose(fp); + } + /* Fade into the background */ f = open("/dev/tty", O_RDWR); if (f >= 0) { @@ -717,6 +728,7 @@ lookup_ipaddr(ifname, addrp, netmaskp) *addrp = ((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr.s_addr; if (ioctl(fd, SIOCGIFNETMASK, (char *) &ifr) < 0) { perror("SIOCGIFNETMASK"); + unlink(_PATH_RARPDPID); exit(1); } *netmaskp = ((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr.s_addr; @@ -915,8 +927,10 @@ va_dcl } vsyslog(LOG_ERR, fmt, ap); va_end(ap); - if (fatal) + if (fatal) { + unlink(_PATH_RARPDPID); exit(1); + } /* NOTREACHED */ }