Use daemon(3) and pidfile(3).
This commit is contained in:
parent
56c5efa335
commit
ad9c4f4fa5
@ -1,4 +1,4 @@
|
|||||||
# $NetBSD: Makefile,v 1.8 1998/04/09 00:32:41 tv Exp $
|
# $NetBSD: Makefile,v 1.9 1999/06/06 03:27:06 thorpej Exp $
|
||||||
# from: Id: Makefile,v 1.5 1993/06/24 05:11:16 deering Exp
|
# from: Id: Makefile,v 1.5 1993/06/24 05:11:16 deering Exp
|
||||||
|
|
||||||
PROG= mrouted
|
PROG= mrouted
|
||||||
@ -6,4 +6,7 @@ SRCS= callout.c cfparse.y config.c igmp.c inet.c kern.c main.c prune.c \
|
|||||||
route.c vif.c
|
route.c vif.c
|
||||||
MAN= mrouted.8
|
MAN= mrouted.8
|
||||||
|
|
||||||
|
LDADD+= -lutil
|
||||||
|
DPADD+= ${LIBUTIL}
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: main.c,v 1.11 1998/05/09 17:22:08 kleink Exp $ */
|
/* $NetBSD: main.c,v 1.12 1999/06/06 03:27:06 thorpej Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The mrouted program is covered by the license in the accompanying file
|
* The mrouted program is covered by the license in the accompanying file
|
||||||
@ -33,13 +33,15 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__RCSID("@(#) $NetBSD: main.c,v 1.11 1998/05/09 17:22:08 kleink Exp $");
|
__RCSID("@(#) $NetBSD: main.c,v 1.12 1999/06/06 03:27:06 thorpej Exp $");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
|
#include <util.h>
|
||||||
|
|
||||||
extern char *configfilename;
|
extern char *configfilename;
|
||||||
char versionstring[100];
|
char versionstring[100];
|
||||||
|
|
||||||
static char pidfilename[] = _PATH_MROUTED_PID;
|
|
||||||
static char dumpfilename[] = _PATH_MROUTED_DUMP;
|
static char dumpfilename[] = _PATH_MROUTED_DUMP;
|
||||||
static char cachefilename[] = _PATH_MROUTED_CACHE;
|
static char cachefilename[] = _PATH_MROUTED_CACHE;
|
||||||
static char genidfilename[] = _PATH_MROUTED_GENID;
|
static char genidfilename[] = _PATH_MROUTED_GENID;
|
||||||
@ -158,29 +160,9 @@ usage: fprintf(stderr,
|
|||||||
/*
|
/*
|
||||||
* Detach from the terminal
|
* Detach from the terminal
|
||||||
*/
|
*/
|
||||||
int t;
|
if (daemon(0, 0))
|
||||||
|
err(1, "can't fork");
|
||||||
if (fork()) exit(0);
|
pidfile(NULL);
|
||||||
(void)close(0);
|
|
||||||
(void)close(1);
|
|
||||||
(void)close(2);
|
|
||||||
(void)open("/", 0);
|
|
||||||
(void)dup2(0, 1);
|
|
||||||
(void)dup2(0, 2);
|
|
||||||
#ifdef SYSV
|
|
||||||
(void)setpgrp();
|
|
||||||
#else
|
|
||||||
#ifdef TIOCNOTTY
|
|
||||||
t = open("/dev/tty", 2);
|
|
||||||
if (t >= 0) {
|
|
||||||
(void)ioctl(t, TIOCNOTTY, (char *)0);
|
|
||||||
(void)close(t);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (setsid() < 0)
|
|
||||||
perror("setsid");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf(stderr, "debug level %u\n", debug);
|
fprintf(stderr, "debug level %u\n", debug);
|
||||||
@ -272,12 +254,6 @@ usage: fprintf(stderr,
|
|||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "pruning %s\n", pruning ? "on" : "off");
|
fprintf(stderr, "pruning %s\n", pruning ? "on" : "off");
|
||||||
|
|
||||||
fp = fopen(pidfilename, "w");
|
|
||||||
if (fp != NULL) {
|
|
||||||
fprintf(fp, "%d\n", (int)getpid());
|
|
||||||
(void) fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)signal(SIGALRM, fasttimer);
|
(void)signal(SIGALRM, fasttimer);
|
||||||
|
|
||||||
(void)signal(SIGHUP, restart);
|
(void)signal(SIGHUP, restart);
|
||||||
|
Loading…
Reference in New Issue
Block a user