Module Name:    src
Committed By:   apb
Date:           Mon Sep 14 19:29:20 UTC 2009

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

Log Message:
Move the code that tries to open _PATH_KSYMS first into a common path,
so that it is used both for the /dev/mem case and the core dump case.

Output from savecore(8) before:
    savecore - - - (null): kvm_openfiles: /netbsd: No such file or directory
and after:
    savecore - - - no core dump


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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.93 src/lib/libkvm/kvm.c:1.94
--- src/lib/libkvm/kvm.c:1.93	Thu Aug 20 11:18:55 2009
+++ src/lib/libkvm/kvm.c	Mon Sep 14 19:29:20 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: kvm.c,v 1.93 2009/08/20 11:18:55 he Exp $	*/
+/*	$NetBSD: kvm.c,v 1.94 2009/09/14 19:29:20 apb 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.93 2009/08/20 11:18:55 he Exp $");
+__RCSID("$NetBSD: kvm.c,v 1.94 2009/09/14 19:29:20 apb Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -324,6 +324,29 @@
 	if (sf == 0)
 		sf = _PATH_DRUM;
 
+	/*
+	 * Open the kernel namelist.  If /dev/ksyms doesn't
+	 * exist, open the current kernel.
+	 */
+	if (ufgiven == 0)
+		kd->nlfd = open_cloexec(_PATH_KSYMS, O_RDONLY, 0);
+	if (kd->nlfd < 0) {
+		if ((kd->nlfd = open_cloexec(uf, O_RDONLY, 0)) < 0) {
+			_kvm_syserr(kd, kd->program, "%s", uf);
+			goto failed;
+		}
+	} else {
+		/*
+		 * 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_cloexec(mf, flag, 0)) < 0) {
 		_kvm_syserr(kd, kd->program, "%s", mf);
 		goto failed;
@@ -350,41 +373,12 @@
 			}
 			/* swap is not configured?  not fatal */
 		}
-		/*
-		 * Open the kernel namelist.  If /dev/ksyms doesn't 
-		 * exist, open the current kernel.
-		 */
-		if (ufgiven == 0)
-			kd->nlfd = open_cloexec(_PATH_KSYMS, O_RDONLY, 0);
-		if (kd->nlfd < 0) {
-			if ((kd->nlfd = open_cloexec(uf, O_RDONLY, 0)) < 0) {
-				_kvm_syserr(kd, kd->program, "%s", uf);
-				goto failed;
-			}
-		} else {
-			/*
-			 * 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;
-		}
 	} else {
 		kd->fdalign = DEV_BSIZE;	/* XXX */
 		/*
 		 * This is a crash dump.
-		 * Initialize the virtual address translation machinery,
-		 * but first setup the namelist fd.
-		 */
-		if ((kd->nlfd = open_cloexec(uf, O_RDONLY, 0)) < 0) {
-			_kvm_syserr(kd, kd->program, "%s", uf);
-			goto failed;
-		}
-
-		/*
+		 * Initialize the virtual address translation machinery.
+		 *
 		 * If there is no valid core header, fail silently here.
 		 * The address translations however will fail without
 		 * header. Things can be made to run by calling

Reply via email to