Date: Thu, 14 Jan 1999 01:50:57 +0100 (CET) From: assar@sics.se To: FreeBSD-gnats-submit@FreeBSD.ORG Cc: Doug Rabson <dfr@nlsystems.com> Subject: kern/9478: support for running a script from kldload and printing data in kldstat Message-ID: <199901140050.BAA00477@assaris.sics.se>
next in thread | raw e-mail | index | archive | help
>Number: 9478 >Category: kern >Synopsis: support for running a script from kldload and printing data in kldstat >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jan 13 16:50:00 PST 1999 >Closed-Date: >Last-Modified: >Originator: Assar Westerlund >Release: FreeBSD 3.0-CURRENT i386 >Organization: none >Environment: >Description: There's no way to figure what major number a dynimcally loaded device driver got assigned. The patches below store that number in the data portion of the module and let kldstat print it out. Also a `-p' options is added to kldload which will run a script with all the data fields of the loaded modules. This can be used to create the device nodes and other tasks that needs to be done. >How-To-Repeat: >Fix: Index: sys/kern/kern_conf.c =================================================================== RCS file: /src/fbsd-repository/src/sys/kern/kern_conf.c,v retrieving revision 1.29 diff -u -w -r1.29 kern_conf.c --- kern_conf.c 1998/11/14 21:58:51 1.29 +++ kern_conf.c 1999/01/14 00:01:31 @@ -169,12 +169,15 @@ cdevsw_module_handler(module_t mod, int what, void *arg) { struct cdevsw_module_data* data = (struct cdevsw_module_data*) arg; + modspecific_t ms; int error; switch (what) { case MOD_LOAD: if (error = cdevsw_add(&data->dev, data->cdevsw, NULL)) return error; + ms.intval = major(data->dev); + module_setspecific(mod, &ms); break; case MOD_UNLOAD: Index: sbin/kldload/kldload.c =================================================================== RCS file: /src/fbsd-repository/src/sbin/kldload/kldload.c,v retrieving revision 1.5 diff -u -w -r1.5 kldload.c --- kldload.c 1998/07/06 06:58:32 1.5 +++ kldload.c 1999/01/14 00:22:45 @@ -33,6 +33,7 @@ #include <stdio.h> #include <unistd.h> #include <sys/param.h> +#include <sys/module.h> #include <sys/linker.h> static void @@ -42,18 +43,55 @@ exit(1); } +#define MAXMODULES 17 + +static void +do_postinstall(char *program, int fileid) +{ + int modid; + char *args[MAXMODULES]; + int i; + + i = 0; + args[i++] = program; + + for (modid = kldfirstmod(fileid); + modid > 0; + modid = modfnext(modid)) { + struct module_stat stat; + + if (i == MAXMODULES - 1) + errx(1, "too many modules in file %d", fileid); + + stat.version = sizeof(stat); + if (modstat(modid, &stat) < 0) + err(1, "can't stat module id %d", modid); + asprintf (&args[i], "%d", stat.data.intval); + if (args[i] == NULL) + err(1, "asprintf"); + ++i; + } + args[i++] = NULL; + execv (program, args); + err (1, "exec %s", program); +} + int main(int argc, char** argv) { int c; int verbose = 0; int fileid; + char *postinstall = NULL; - while ((c = getopt(argc, argv, "v")) != -1) + while ((c = getopt(argc, argv, "vp:")) != -1) switch (c) { case 'v': verbose = 1; break; + case 'p': + postinstall = optarg; + break; default: usage(); } @@ -66,9 +104,12 @@ fileid = kldload(argv[0]); if (fileid < 0) err(1, "can't load %s", argv[0]); - else + else { if (verbose) printf("Loaded %s, id=%d\n", argv[0], fileid); + if (postinstall != NULL) + do_postinstall(postinstall, fileid); + } return 0; } Index: sbin/kldload/kldload.8 =================================================================== RCS file: /src/fbsd-repository/src/sbin/kldload/kldload.8,v retrieving revision 1.5 diff -u -w -u -w -r1.5 kldload.8 --- kldload.8 1998/11/12 11:10:26 1.5 +++ kldload.8 1999/01/14 00:49:20 @@ -34,6 +34,7 @@ .Sh SYNOPSIS .Nm kldload .Op Fl v +.Op Fl p Ar program .Ar filename .Sh DESCRIPTION The @@ -46,6 +47,11 @@ .Bl -tag -width indent .It Fl v Be more verbose. +.It Fl p Ar program +Run +.Ar program +with the data fields from the loaded modules as arguments. This can +be used to e.g. create the needed device nodes. .El .Sh FILES .Bl -tag -width /modules -compact Index: sbin/kldstat/kldstat.c =================================================================== RCS file: /src/fbsd-repository/src/sbin/kldstat/kldstat.c,v retrieving revision 1.5 diff -u -w -r1.5 kldstat.c --- kldstat.c 1998/11/07 00:29:09 1.5 +++ kldstat.c 1999/01/14 00:23:22 @@ -46,8 +46,12 @@ stat.version = sizeof(struct module_stat); if (modstat(modid, &stat) < 0) warn("can't stat module id %d", modid); - else - printf("\t\t%2d %s\n", stat.id, stat.name); + else { + printf("\t\t%2d %s", stat.id, stat.name); + if (stat.data.intval) + printf(" (%d)", stat.data.intval); + printf("\n"); + } } static void printfile(int fileid, int verbose) >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901140050.BAA00477>