diff options
author | des <des@FreeBSD.org> | 2003-11-17 11:08:28 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2003-11-17 11:08:28 +0000 |
commit | 6c6b3db302af35692b8ba84bc751d8284c17b975 (patch) | |
tree | f9de9a76be21fa75065e7d158a1b516a57923d7c /usr.sbin | |
parent | acbbfb5fbdc673eb065b6639fc4da8d5bed7dfd8 (diff) | |
download | FreeBSD-src-6c6b3db302af35692b8ba84bc751d8284c17b975.zip FreeBSD-src-6c6b3db302af35692b8ba84bc751d8284c17b975.tar.gz |
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 <rehsack@liwing.de>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/moused/moused.c | 40 |
1 files changed, 38 insertions, 2 deletions
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 <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 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) { |