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
@ -35,7 +35,7 @@
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";
#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
@ -125,6 +125,7 @@ extern int dkinit __P((int, gid_t));
void updatestat __P((int));
void setup __P((void));
void setup_kd_once __P((void));
void stat_init __P((void));
int havedisk __P((void));
void rstat_service __P((struct svc_req *, SVCXPRT *));
@ -323,17 +324,32 @@ updatestat(dummy)
}
void
setup()
setup_kd_once()
{
struct ifnet ifnet;
long off;
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
setup()
{
struct ifnet ifnet;
long off;
static int is_kfd_setup = 0;
/* setup() is called after each dormant->active
* transition. Since we never close the kvm files
* (there's no reason), make sure we don't open them
* 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) {
syslog(LOG_ERR, "can't get namelist");