Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/rpc.rstatd Avoid an open-file leak when not inetd-sp...
details: https://anonhg.NetBSD.org/src/rev/c5854d0197fc
branches: trunk
changeset: 467502:c5854d0197fc
user: bgrayson <bgrayson%NetBSD.org@localhost>
date: Thu Mar 25 08:07:47 1999 +0000
description:
Avoid an open-file leak when not inetd-spawned: only call kvm_openfiles() once
diffstat:
libexec/rpc.rstatd/rstat_proc.c | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
diffs (63 lines):
diff -r b9b5583163a9 -r c5854d0197fc libexec/rpc.rstatd/rstat_proc.c
--- a/libexec/rpc.rstatd/rstat_proc.c Thu Mar 25 07:00:43 1999 +0000
+++ b/libexec/rpc.rstatd/rstat_proc.c Thu Mar 25 08:07:47 1999 +0000
@@ -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 @@
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,16 +324,31 @@
}
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) {
Home |
Main Index |
Thread Index |
Old Index