[PATCH] /usr/sbin/moused fails if ums is built into kernel

Jens Rehsack rehsack at liwing.de
Mon Nov 17 02:55:46 PST 2003


>Submitter-Id:	current-users
>Originator:	Jens Rehsack
>Organization:	LiWing IT-Services
>Confidential:	no
>Synopsis:	[PATCH] /usr/sbin/moused fails if ums is built into kernel
>Severity:	serious
>Priority:	high
>Category:	bin
>Class:		sw-bug
>Release:	FreeBSD 5.1-CURRENT i386
>Environment:
System: FreeBSD statler 5.1-CURRENT FreeBSD 5.1-CURRENT #0: Sat Nov 15 14:11:24 GMT 2003 root at statler:/usr/obj/usr/src/sys/STATLER i386


	
>Description:
	If the device ums is built into the kernel and not as module,
	and the module is not build (eg. excluded by MODULES_OVERRIDE),
	moused fails with:
	'unable to load USB mouse driver: No such file or directory'
>How-To-Repeat:
	Build a -CURRENT kernel with ums, don't build the ums module,
	use an usb-mouse and reboot.
>Fix:

	

--- patch-usr.sbin::moused::moused.c begins here ---
Index: usr.sbin/moused/moused.c
===================================================================
diff -u usr.sbin/moused/moused.c.orig usr.sbin/moused/moused.c
--- usr.sbin/moused/moused.c.orig	Sat Nov 15 14:51:14 2003
+++ usr.sbin/moused/moused.c	Sat Nov 15 15:08:10 2003
@@ -70,6 +70,9 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/un.h>
+#include <sys/param.h>
+#include <sys/linker.h>
+#include <sys/module.h>
 #include <unistd.h>
 
 #define MAX_CLICKTHRESHOLD	2000	/* 2 seconds */
@@ -495,6 +498,8 @@
 
 static int kidspad(u_char rxc, mousestatus_t *act);
 
+static int usbmodule(void);
+
 int
 main(int argc, char *argv[])
 {
@@ -754,8 +759,7 @@
 
     retry = 1;
     if (strncmp(rodent.portname, "/dev/ums", 8) == 0) {
-	if (kldload("ums") == -1 && errno != EEXIST)
-	    logerr(1, "unable to load USB mouse driver");
+	usbmodule();
 	retry = 5;
     }
 
@@ -824,6 +828,43 @@
     /* NOT REACHED */
 
     exit(0);
+}
+
+static int
+usbmodule(void)
+{
+	int fileid, modid, loaded = 0;
+	struct kld_file_stat fstat;
+	struct module_stat mstat;
+
+	for( fileid = kldnext(0); loaded == 0 && fileid > 0;
+	     fileid = kldnext(fileid) )
+	{
+		fstat.version = sizeof(fstat);
+		if( kldstat( fileid, &fstat ) < 0 )
+			continue;
+		if( strncmp( fstat.name, "uhub/ums", 8 ) == 0 )
+		{
+			loaded = 1;
+			break;
+		}
+
+		for( modid = kldfirstmod(fileid); modid > 0;
+		     modid = modfnext(modid) )
+		{
+			mstat.version = sizeof(mstat);
+			if( modstat( modid, &mstat ) < 0 )
+				continue;
+			if( strncmp( mstat.name, "uhub/ums", 8 ) == 0 )
+			{
+				loaded = 1;
+				break;
+			}
+		}
+	}
+
+	if( !loaded && kldload("ums") == -1 && errno != EEXIST )
+	    logerr(1, "unable to load USB mouse driver");
 }
 
 static void
--- patch-usr.sbin::moused::moused.c ends here ---




More information about the freebsd-current mailing list