diff options
author | Bill Nottingham <notting@redhat.com> | 2004-11-23 04:54:00 +0000 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2004-11-23 04:54:00 +0000 |
commit | 772f9e8178398cc84dd37e5b831fc2376caa39dc (patch) | |
tree | 9745e9b8ffcba79777add5f7c21d2317b7658db5 /src | |
parent | 3b87c16c191cbd5ecf9238ad4bdb8411429a473e (diff) | |
download | initscripts-772f9e8178398cc84dd37e5b831fc2376caa39dc.tar initscripts-772f9e8178398cc84dd37e5b831fc2376caa39dc.tar.gz initscripts-772f9e8178398cc84dd37e5b831fc2376caa39dc.tar.bz2 initscripts-772f9e8178398cc84dd37e5b831fc2376caa39dc.tar.xz initscripts-772f9e8178398cc84dd37e5b831fc2376caa39dc.zip |
backport
Diffstat (limited to 'src')
-rw-r--r-- | src/kmodule.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/kmodule.c b/src/kmodule.c index 5b0340ee..fb78e3e7 100644 --- a/src/kmodule.c +++ b/src/kmodule.c @@ -10,7 +10,7 @@ */ #include <ctype.h> -#include <ftw.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,40 +19,50 @@ #include <popt.h> +#include <sys/mman.h> #include <sys/utsname.h> #include <kudzu/kudzu.h> - -/* HACK. This is so not thread-safe. */ -static char mod_name[100], cmod_name[100]; - -static int isModule(const char *filename, const struct stat *sb, int flag) { - char *fname = basename(filename); - if ((!strcmp(fname,mod_name) || !strcmp(fname,cmod_name))) { - return 1; +char *setupFile() +{ + struct stat sbuf; + char path[512]; + int fd; + struct utsname utsbuf; + char *buf = NULL; + + uname(&utsbuf); + snprintf(path,512,"/lib/modules/%s/modules.dep",utsbuf.release); + if (!stat(path,&sbuf)) { + fd = open(path,O_RDONLY); + buf = malloc(sbuf.st_size + 1); + read(fd,buf,sbuf.st_size); + buf[sbuf.st_size] = '\0'; + close(fd); } - return 0; + return buf; } - int isAvailable(char *modulename) { - struct utsname utsbuf; - char path[512]; + char mod_name[100]; + static char *buf = NULL; - uname(&utsbuf); - snprintf(mod_name,100,"%s.ko",modulename); - snprintf(cmod_name,100,"%s.ko.gz",modulename); - snprintf(path,512,"/lib/modules/%s/kernel",utsbuf.release); - /* Do not set the third argument of this function to < 6. Blarg. */ - if (ftw(path,isModule,15) == 1) { - return 1; + if (!buf) { + buf = setupFile(); + if (!buf) + return 0; } + snprintf(mod_name,100,"/%s.ko:",modulename); + if (strstr(buf,mod_name)) + return 1; + snprintf(mod_name,100,"/%s.ko.gz:",modulename); + if (strstr(buf,mod_name)) + return 1; return 0; } - int main(int argc, char **argv) { char *bus = NULL, *class = NULL; |