From 6c6b3db302af35692b8ba84bc751d8284c17b975 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 17 Nov 2003 11:08:28 +0000 Subject: Instead of blindly loading the ums module and bailing out if that fails, check if it's already loaded or compiled into the kernel, and only try to load it if it isn't. PR: bin/59368 Submitted by: Jens Rehsack --- usr.sbin/moused/moused.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'usr.sbin/moused/moused.c') diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c index e1c848e..b77e82a 100644 --- a/usr.sbin/moused/moused.c +++ b/usr.sbin/moused/moused.c @@ -70,6 +70,9 @@ static const char rcsid[] = #include #include #include +#include +#include +#include #include #define MAX_CLICKTHRESHOLD 2000 /* 2 seconds */ @@ -495,6 +498,8 @@ static void mremote_clientchg(int add); static int kidspad(u_char rxc, mousestatus_t *act); +static int usbmodule(void); + int main(int argc, char *argv[]) { @@ -754,8 +759,7 @@ main(int argc, char *argv[]) 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; } @@ -826,6 +830,38 @@ main(int argc, char *argv[]) exit(0); } +static int +usbmodule(void) +{ + struct kld_file_stat fstat; + struct module_stat mstat; + int fileid, modid; + int loaded; + + for (loaded = 0, fileid = kldnext(0); !loaded && 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 moused(void) { -- cgit v1.1