Avoid an open-file leak when not inetd-spawned: only call kvm_openfiles() once

This commit is contained in:
bgrayson 1999-03-25 08:07:47 +00:00
parent 29fbd4fd08
commit 085184c276

View File

@ -1,4 +1,4 @@
/* $NetBSD: rstat_proc.c,v 1.28 1999/03/24 05:50:50 mrg Exp $ */ /* $NetBSD: rstat_proc.c,v 1.29 1999/03/25 08:07:47 bgrayson Exp $ */
/* /*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@ -35,7 +35,7 @@
static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro"; static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";
static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC"; static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";
#else #else
__RCSID("$NetBSD: rstat_proc.c,v 1.28 1999/03/24 05:50:50 mrg Exp $"); __RCSID("$NetBSD: rstat_proc.c,v 1.29 1999/03/25 08:07:47 bgrayson Exp $");
#endif #endif
#endif #endif
@ -125,6 +125,7 @@ extern int dkinit __P((int, gid_t));
void updatestat __P((int)); void updatestat __P((int));
void setup __P((void)); void setup __P((void));
void setup_kd_once __P((void));
void stat_init __P((void)); void stat_init __P((void));
int havedisk __P((void)); int havedisk __P((void));
void rstat_service __P((struct svc_req *, SVCXPRT *)); void rstat_service __P((struct svc_req *, SVCXPRT *));
@ -322,17 +323,32 @@ updatestat(dummy)
alarm(1); alarm(1);
} }
void
setup_kd_once()
{
char errbuf[_POSIX2_LINE_MAX];
kfd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
if (kfd == NULL) {
syslog(LOG_ERR, "%s", errbuf);
exit (1);
}
}
void void
setup() setup()
{ {
struct ifnet ifnet; struct ifnet ifnet;
long off; long off;
char errbuf[_POSIX2_LINE_MAX]; static int is_kfd_setup = 0;
kfd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); /* setup() is called after each dormant->active
if (kfd == NULL) { * transition. Since we never close the kvm files
syslog(LOG_ERR, "%s", errbuf); * (there's no reason), make sure we don't open them
exit (1); * each time, as that can lead to exhaustion of all open
* files! */
if (!is_kfd_setup) {
setup_kd_once();
is_kfd_setup = 1;
} }
if (kvm_nlist(kfd, nl) != 0) { if (kvm_nlist(kfd, nl) != 0) {