Source-Changes-HG archive

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

[src/trunk]: src/sbin/modload If no other name is specified, and machdep.boot...



details:   https://anonhg.NetBSD.org/src/rev/96d497f06834
branches:  trunk
changeset: 542859:96d497f06834
user:      atatat <atatat%NetBSD.org@localhost>
date:      Sun Feb 09 23:29:32 2003 +0000

description:
If no other name is specified, and machdep.booted_kernel is present
and names a file, use that as a the default kernel, otherwise fall
back to /netbsd.

Makes lkms work *much* better when you're testing kernels that are not
named /netbsd.

diffstat:

 sbin/modload/modload.c |  34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)

diffs (69 lines):

diff -r 58b3d82f62a5 -r 96d497f06834 sbin/modload/modload.c
--- a/sbin/modload/modload.c    Sun Feb 09 22:33:18 2003 +0000
+++ b/sbin/modload/modload.c    Sun Feb 09 23:29:32 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: modload.c,v 1.35 2002/10/10 01:57:10 simonb Exp $      */
+/*     $NetBSD: modload.c,v 1.36 2003/02/09 23:29:32 atatat Exp $      */
 
 /*
  * Copyright (c) 1993 Terrence R. Lambert.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: modload.c,v 1.35 2002/10/10 01:57:10 simonb Exp $");
+__RCSID("$NetBSD: modload.c,v 1.36 2003/02/09 23:29:32 atatat Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -44,6 +44,8 @@
 #include <sys/lkm.h>
 #include <sys/stat.h>
 #include <sys/file.h>
+#include <sys/sysctl.h>
+#include <machine/cpu.h>
 #include <err.h>
 #include <errno.h>
 #include <stdio.h>
@@ -242,7 +244,7 @@
 main(int argc, char **argv)
 {
        int c;
-       char *kname = _PATH_UNIX;
+       char *kname = NULL;
        char *entry = DFLT_ENTRY;
        char *post = NULL;
        char *ldscript = NULL;
@@ -349,6 +351,32 @@
        }
 
        /*
+        * Determine name of kernel to use
+        */
+       if (kname == NULL) {
+#ifdef CPU_BOOTED_KERNEL
+               /* 130 is 128 + '/' + '\0' */
+               static char booted_kernel[130];
+               int mib[2], rc;
+               size_t len;
+               struct stat st;
+
+               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';
+               kname = (booted_kernel[1] == '/') ?
+                   &booted_kernel[1] : &booted_kernel[0];
+               if (rc != -1)
+                       rc = stat(kname, &st);
+               if (rc == -1 || !S_ISREG(st.st_mode))
+#endif /* CPU_BOOTED_KERNEL */
+                       kname = _PATH_UNIX;
+       }
+       /*
         * Prelink to get file size
         */
        if (prelink(kname, entry, out, 0, modobj, ldscript))



Home | Main Index | Thread Index | Old Index