Module Name:    src
Committed By:   maxv
Date:           Wed Feb  7 14:03:18 UTC 2018

Modified Files:
        src/lib/libkvm: kvm.c

Log Message:
Keep /dev/ksyms open in _kvm_open(). This way /dev/ksyms can be put into
$g_kmem without breaking the tools that need kmem+ksyms.

Discussed on tech-kern@ three weeks ago. The original issue was reported
by maya@, the patch was written by Tom Ivar Helbekkmo, ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/lib/libkvm/kvm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libkvm/kvm.c
diff -u src/lib/libkvm/kvm.c:1.102 src/lib/libkvm/kvm.c:1.103
--- src/lib/libkvm/kvm.c:1.102	Tue Mar 29 06:51:40 2016
+++ src/lib/libkvm/kvm.c	Wed Feb  7 14:03:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kvm.c,v 1.102 2016/03/29 06:51:40 mrg Exp $	*/
+/*	$NetBSD: kvm.c,v 1.103 2018/02/07 14:03:18 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)kvm.c	8.2 (Berkeley) 2/13/94";
 #else
-__RCSID("$NetBSD: kvm.c,v 1.102 2016/03/29 06:51:40 mrg Exp $");
+__RCSID("$NetBSD: kvm.c,v 1.103 2018/02/07 14:03:18 maxv Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -322,15 +322,6 @@ _kvm_open(kvm_t *kd, const char *uf, con
 		strlcpy(kd->kernelname, uf, sizeof(kd->kernelname));
 	} else {
 		strlcpy(kd->kernelname, _PATH_KSYMS, sizeof(kd->kernelname));
-		/*
-		 * We're here because /dev/ksyms was opened
-		 * successfully.  However, we don't want to keep it
-		 * open, so we close it now.  Later, we will open
-		 * it again, since it will be the only case where
-		 * kd->nlfd is negative.
-		 */
-		close(kd->nlfd);
-		kd->nlfd = -1;
 	}
 
 	if ((kd->pmfd = open(mf, flag | O_CLOEXEC, 0)) < 0) {
@@ -769,33 +760,16 @@ kvm_close(kvm_t *kd)
 int
 kvm_nlist(kvm_t *kd, struct nlist *nl)
 {
-	int rv, nlfd;
-
-	/*
-	 * kd->nlfd might be negative when we get here, and in that
-	 * case that means that we're using /dev/ksyms.
-	 * So open it again, just for the time we retrieve the list.
-	 */
-	if (kd->nlfd < 0) {
-		nlfd = open(_PATH_KSYMS, O_RDONLY | O_CLOEXEC, 0);
-		if (nlfd < 0) {
-			_kvm_err(kd, 0, "failed to open %s", _PATH_KSYMS);
-			return (nlfd);
-		}
-	} else
-		nlfd = kd->nlfd;
+	int rv;
 
 	/*
 	 * Call the nlist(3) routines to retrieve the given namelist.
 	 */
-	rv = __fdnlist(nlfd, nl);
+	rv = __fdnlist(kd->nlfd, nl);
 
 	if (rv == -1)
 		_kvm_err(kd, 0, "bad namelist");
 
-	if (kd->nlfd < 0)
-		close(nlfd);
-
 	return (rv);
 }
 

Reply via email to