From assar@sics.se  Wed Jan 13 16:50:31 1999
Received: from assaris.sics.se (assaris.sics.se [193.10.66.108])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA00754
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 13 Jan 1999 16:50:29 -0800 (PST)
          (envelope-from assar@sics.se)
Received: (from assar@localhost) by assaris.sics.se (8.9.1/8.7.3) id BAA00477; Thu, 14 Jan 1999 01:50:57 +0100 (CET)
Message-Id: <199901140050.BAA00477@assaris.sics.se>
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: support for running a script from kldload and printing data in kldstat
X-Send-Pr-Version: 3.2

>Number:         9478
>Category:       kern
>Synopsis:       [patch] support for running a script from kldload and printing data in kldstat
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 13 16:50:00 PST 1999
>Closed-Date:    Sat Jul 30 01:09:58 GMT 2005
>Last-Modified:  Sat Jul 30 01:09:58 GMT 2005
>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:
Responsible-Changed-From-To: freebsd-bugs->assar 
Responsible-Changed-By: mike 
Responsible-Changed-When: Thu Jul 19 14:43:50 PDT 2001 
Responsible-Changed-Why:  

Originator is a committer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=9478 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Thu Aug 26 03:00:59 GMT 2004 
State-Changed-Why:  
Is this still a problem with modern versions of FreeBSD? 


Responsible-Changed-From-To: assar->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Aug 26 03:00:59 GMT 2004 
Responsible-Changed-Why:  
With bugmeister hat on, reassign from inactive committer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=9478 
State-Changed-From-To: feedback->closed 
State-Changed-By: kris 
State-Changed-When: Sat Jul 30 01:09:51 GMT 2005 
State-Changed-Why:  
Feedback timeout 

http://www.freebsd.org/cgi/query-pr.cgi?pr=9478 
>Unformatted:
