Current-Users archive

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

savecore can't dump



The following patch "works for me" - suggestions on improvements, and which
man page I should edit welcome :-)

Cheers,

Patrick
Index: sbin/savecore/savecore.c
===================================================================
RCS file: /cvsroot/src/sbin/savecore/savecore.c,v
retrieving revision 1.80
diff -u -r1.80 savecore.c
--- sbin/savecore/savecore.c    6 Apr 2009 12:32:30 -0000       1.80
+++ sbin/savecore/savecore.c    18 Jun 2009 10:46:05 -0000
@@ -228,6 +228,9 @@
        if (!clear)
                dirname = argv[0];
 
+       if (!kernel)
+               kernel = kvm_get_booted_kernel();
+
        (void)time(&now);
        kmem_setup();
 
Index: lib/libkvm/kvm.c
===================================================================
RCS file: /cvsroot/src/lib/libkvm/kvm.c,v
retrieving revision 1.92
diff -u -r1.92 kvm.c
--- lib/libkvm/kvm.c    15 Jan 2008 14:16:30 -0000      1.92
+++ lib/libkvm/kvm.c    18 Jun 2009 10:46:05 -0000
@@ -238,6 +238,35 @@
        return (rv);
 }
 
+const char *kvm_get_booted_kernel(void) {
+       const char *uf;
+#ifdef CPU_BOOTED_KERNEL
+       struct stat st;
+       /* 130 is 128 + '/' + '\0' */
+       static char booted_kernel[130];
+       int mib[2], rc;
+       size_t len;
+
+       mib[0] = CTL_MACHDEP;
+       mib[1] = CPU_BOOTED_KERNEL;
+       booted_kernel[0] = '/';
+       booted_kernel[1] = '\0';
+       len = sizeof(booted_kernel) - 2;
+       rc = sysctl(&mib[0], 2, &booted_kernel[1], &len, NULL, 0);
+       booted_kernel[sizeof(booted_kernel) - 1] = '\0';
+       uf = (booted_kernel[1] == '/') ?
+           &booted_kernel[1] : &booted_kernel[0];
+       if (rc != -1)
+               rc = stat(uf, &st);
+       if (rc != -1 && !S_ISREG(st.st_mode))
+               rc = -1;
+       if (rc == -1)
+#endif /* CPU_BOOTED_KERNEL */
+               uf = _PATH_UNIX;
+
+       return uf;
+}
+
 static kvm_t *
 _kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf, int flag,
     char *errout)
@@ -287,30 +316,8 @@
        }
 
        ufgiven = (uf != NULL);
-       if (!ufgiven) {
-#ifdef CPU_BOOTED_KERNEL
-               /* 130 is 128 + '/' + '\0' */
-               static char booted_kernel[130];
-               int mib[2], rc;
-               size_t len;
-
-               mib[0] = CTL_MACHDEP;
-               mib[1] = CPU_BOOTED_KERNEL;
-               booted_kernel[0] = '/';
-               booted_kernel[1] = '\0';
-               len = sizeof(booted_kernel) - 2;
-               rc = sysctl(&mib[0], 2, &booted_kernel[1], &len, NULL, 0);
-               booted_kernel[sizeof(booted_kernel) - 1] = '\0';
-               uf = (booted_kernel[1] == '/') ?
-                   &booted_kernel[1] : &booted_kernel[0];
-               if (rc != -1)
-                       rc = stat(uf, &st);
-               if (rc != -1 && !S_ISREG(st.st_mode))
-                       rc = -1;
-               if (rc == -1)
-#endif /* CPU_BOOTED_KERNEL */
-                       uf = _PATH_UNIX;
-       }
+       if (!ufgiven)
+               uf = kvm_get_booted_kernel();
        else if (strlen(uf) >= MAXPATHLEN) {
                _kvm_err(kd, kd->program, "exec file name too long");
                goto failed;
Index: include/kvm.h
===================================================================
RCS file: /cvsroot/src/include/kvm.h,v
retrieving revision 1.15
diff -u -r1.15 kvm.h
--- include/kvm.h       8 Nov 2007 20:48:04 -0000       1.15
+++ include/kvm.h       18 Jun 2009 10:46:05 -0000
@@ -77,6 +77,7 @@
 struct kinfo_proc *
          kvm_getprocs(kvm_t *, int, int, int *);
 int      kvm_nlist(kvm_t *, struct nlist *);
+const char *kvm_get_booted_kernel(void);
 kvm_t   *kvm_open
            (const char *, const char *, const char *, int, const char *);
 kvm_t   *kvm_openfiles(const char *, const char *, const char *, int, char *);


Home | Main Index | Thread Index | Old Index