diff --git a/libexec/rpc.rstatd/rstat_proc.c b/libexec/rpc.rstatd/rstat_proc.c index 0e3d36c540ed..aafb22ced904 100644 --- a/libexec/rpc.rstatd/rstat_proc.c +++ b/libexec/rpc.rstatd/rstat_proc.c @@ -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 *)); @@ -322,17 +323,32 @@ updatestat(dummy) 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 setup() { struct ifnet ifnet; long off; - char errbuf[_POSIX2_LINE_MAX]; + static int is_kfd_setup = 0; - kfd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); - if (kfd == NULL) { - syslog(LOG_ERR, "%s", errbuf); - exit (1); + /* 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) {