Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libkvm Move the code that tries to open _PATH_KSYMS firs...



details:   https://anonhg.NetBSD.org/src/rev/39a88e36f6d2
branches:  trunk
changeset: 747436:39a88e36f6d2
user:      apb <apb%NetBSD.org@localhost>
date:      Mon Sep 14 19:29:20 2009 +0000

description:
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

diffstat:

 lib/libkvm/kvm.c |  60 +++++++++++++++++++++++++------------------------------
 1 files changed, 27 insertions(+), 33 deletions(-)

diffs (92 lines):

diff -r 7d60d6dbedd2 -r 39a88e36f6d2 lib/libkvm/kvm.c
--- a/lib/libkvm/kvm.c  Mon Sep 14 17:34:56 2009 +0000
+++ b/lib/libkvm/kvm.c  Mon Sep 14 19:29:20 2009 +0000
@@ -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



Home | Main Index | Thread Index | Old Index