Index: stable/9/sbin/kldload/kldload.c =================================================================== --- stable/9/sbin/kldload/kldload.c (revision 260908) +++ stable/9/sbin/kldload/kldload.c (revision 260909) @@ -1,199 +1,214 @@ /*- * Copyright (c) 1997 Doug Rabson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #define PATHCTL "kern.module_path" static int path_check(const char *, int); static void usage(void); /* * Check to see if the requested module is specified as a filename with no * path. If so and if a file by the same name exists in the module path, * warn the user that the module in the path will be used in preference. */ static int path_check(const char *kldname, int quiet) { int mib[5], found; size_t miblen, pathlen; char kldpath[MAXPATHLEN]; char *path, *tmppath, *element; struct stat sb; dev_t dev; ino_t ino; if (strchr(kldname, '/') != NULL) { return (0); } if (strstr(kldname, ".ko") == NULL) { return (0); } if (stat(kldname, &sb) != 0) { return (0); } found = 0; dev = sb.st_dev; ino = sb.st_ino; miblen = sizeof(mib) / sizeof(mib[0]); if (sysctlnametomib(PATHCTL, mib, &miblen) != 0) { err(1, "sysctlnametomib(%s)", PATHCTL); } if (sysctl(mib, miblen, NULL, &pathlen, NULL, 0) == -1) { err(1, "getting path: sysctl(%s) - size only", PATHCTL); } path = malloc(pathlen + 1); if (path == NULL) { err(1, "allocating %lu bytes for the path", (unsigned long)pathlen + 1); } if (sysctl(mib, miblen, path, &pathlen, NULL, 0) == -1) { err(1, "getting path: sysctl(%s)", PATHCTL); } tmppath = path; while ((element = strsep(&tmppath, ";")) != NULL) { strlcpy(kldpath, element, MAXPATHLEN); if (kldpath[strlen(kldpath) - 1] != '/') { strlcat(kldpath, "/", MAXPATHLEN); } strlcat(kldpath, kldname, MAXPATHLEN); if (stat(kldpath, &sb) == -1) { continue; } found = 1; if (sb.st_dev != dev || sb.st_ino != ino) { if (!quiet) { warnx("%s will be loaded from %s, not the " "current directory", kldname, element); } break; } else if (sb.st_dev == dev && sb.st_ino == ino) { break; } } free(path); if (!found) { if (!quiet) { warnx("%s is not in the module path", kldname); } return (-1); } return (0); } static void usage(void) { fprintf(stderr, "usage: kldload [-nqv] file ...\n"); exit(1); } int main(int argc, char** argv) { int c; int errors; int fileid; int verbose; int quiet; int check_loaded; errors = 0; verbose = 0; quiet = 0; check_loaded = 0; while ((c = getopt(argc, argv, "nqv")) != -1) { switch (c) { case 'q': quiet = 1; verbose = 0; break; case 'v': verbose = 1; quiet = 0; break; case 'n': check_loaded = 1; break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0) usage(); while (argc-- != 0) { if (path_check(argv[0], quiet) == 0) { fileid = kldload(argv[0]); if (fileid < 0) { if (check_loaded != 0 && errno == EEXIST) { if (verbose) printf("%s is already " "loaded\n", argv[0]); } else { - warn("can't load %s", argv[0]); + switch (errno) { + case EEXIST: + warnx("can't load %s: module " + "already loaded or " + "in kernel", argv[0]); + break; + case ENOEXEC: + warnx("an error occurred while " + "loading the module. " + "Please check dmesg(8) for " + "more details."); + break; + default: + warn("can't load %s", argv[0]); + break; + } errors++; } } else { if (verbose) printf("Loaded %s, id=%d\n", argv[0], fileid); } } else { errors++; } argv++; } return (errors ? 1 : 0); } Index: stable/9/sbin/kldload =================================================================== --- stable/9/sbin/kldload (revision 260908) +++ stable/9/sbin/kldload (revision 260909) Property changes on: stable/9/sbin/kldload ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sbin/kldload:r260483-260484,260594,260596-260597 Index: stable/9/sbin =================================================================== --- stable/9/sbin (revision 260908) +++ stable/9/sbin (revision 260909) Property changes on: stable/9/sbin ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sbin:r260483-260484,260594,260596-260597 Index: stable/9/share/man/man4/kld.4 =================================================================== --- stable/9/share/man/man4/kld.4 (revision 260908) +++ stable/9/share/man/man4/kld.4 (revision 260909) @@ -1,175 +1,175 @@ .\" Copyright (c) 1993 Christopher G. Demetriou .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. The name of the author may not be used to endorse or promote products .\" derived from this software without specific prior written permission .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd November 8, 1998 +.Dd January 13, 2014 .Dt KLD 4 .Os .Sh NAME .Nm kld .Nd dynamic kernel linker facility .Sh DESCRIPTION The LKM (Loadable Kernel Modules) facility has been deprecated in .Fx 3.0 and above in favor of the .Nm interface. This interface, like its predecessor, allows the system administrator to dynamically add and remove functionality from a running system. This ability also helps software developers to develop new parts of the kernel without constantly rebooting to test their changes. .Pp Various types of modules can be loaded into the system. There are several defined module types, listed below, which can be added to the system in a predefined way. In addition, there is a generic type, for which the module itself handles loading and unloading. .Pp The .Fx system makes extensive use of loadable kernel modules, and provides loadable versions of most file systems, the .Tn NFS client and server, all the screen-savers, and the .Tn iBCS2 and .Tn Linux emulators. .Nm modules are placed by default in the .Pa /boot/kernel directory along with their matching kernel. .Pp The .Nm interface is used through the .Xr kldload 8 , .Xr kldunload 8 and .Xr kldstat 8 programs. .Pp The .Xr kldload 8 program can load either .Xr a.out 5 or ELF formatted loadable modules. The .Xr kldunload 8 program unloads any given loaded module, if no other module is dependent upon the given module. The .Xr kldstat 8 program is used to check the status of the modules currently loaded into the system. .Pp Kernel modules may only be loaded or unloaded if the system security level .Va kern.securelevel is less than one. .Sh "MODULE TYPES" .Bl -ohang .It Em "Device Driver modules" New block and character device drivers may be loaded into the system with .Nm . Device nodes for the loaded drivers are automatically created when a module is loaded and destroyed when it is unloaded by .Xr devfs 5 . You can specify userland programs that will run when new devices become available as a result of loading modules, or existing devices go away when modules are unloaded, by configuring .Xr devd 8 . .El .Sh FILES .Bl -tag -width /usr/include/sys/module.h -compact .It Pa /boot/kernel directory containing module binaries built for the kernel also residing in the directory. .It Pa /usr/include/sys/module.h file containing definitions required to compile a .Nm module .It Pa /usr/share/examples/kld example source code implementing a sample kld module .El .Sh SEE ALSO .Xr kldfind 2 , .Xr kldfirstmod 2 , .Xr kldload 2 , .Xr kldnext 2 , .Xr kldstat 2 , .Xr kldunload 2 , .Xr devfs 5 , .Xr devd 8 , .Xr kldload 8 , .Xr kldstat 8 , .Xr kldunload 8 , .Xr sysctl 8 .Sh HISTORY The .Nm facility appeared in .Fx 3.0 and was designed as a replacement for the .Nm lkm facility, which was similar in functionality to the loadable kernel modules facility provided by .Tn SunOS 4.1.3. .Sh AUTHORS The .Nm facility was originally implemented by .An Doug Rabson Aq dfr@FreeBSD.org . .Sh BUGS If a module B, is dependent on another module A, but is not compiled with module A as a dependency, then .Xr kldload 8 fails to load module B, even if module A is already present in the system. .Pp If multiple modules are dependent on module A, and are compiled with module A as a dependency, then .Xr kldload 8 loads an instance of module A when any of the modules are loaded. .Pp If a custom entry point is used for a module, and the module is compiled as an .Sq ELF binary, then .Xr kldload 8 fails to execute the entry point. .Pp .Xr kldload 8 -returns the cryptic message -.Sq Li "ENOEXEC (Exec format error)" +points the user to read +.Xr dmesg 8 for any error encountered while loading a module. .Pp When system internal interfaces change, old modules often cannot detect this, and such modules when loaded will often cause crashes or mysterious failures. Index: stable/9/share/man/man4 =================================================================== --- stable/9/share/man/man4 (revision 260908) +++ stable/9/share/man/man4 (revision 260909) Property changes on: stable/9/share/man/man4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/share/man/man4:r260595,260597 Index: stable/9/share/man =================================================================== --- stable/9/share/man (revision 260908) +++ stable/9/share/man (revision 260909) Property changes on: stable/9/share/man ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/share/man:r260595,260597 Index: stable/9/share =================================================================== --- stable/9/share (revision 260908) +++ stable/9/share (revision 260909) Property changes on: stable/9/share ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/share:r260595,260597