aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2004-11-23 03:28:54 +0000
committerBill Nottingham <notting@redhat.com>2004-11-23 03:28:54 +0000
commitb13728c31b0e0e84589234a25a5d4d72f3594155 (patch)
treec317f6a2aad12199d3b8b5f0eef9c763cabca644
parentddef4757714ccc9d566b0fba4494528c32bcaa9d (diff)
downloadinitscripts-b13728c31b0e0e84589234a25a5d4d72f3594155.tar
initscripts-b13728c31b0e0e84589234a25a5d4d72f3594155.tar.gz
initscripts-b13728c31b0e0e84589234a25a5d4d72f3594155.tar.bz2
initscripts-b13728c31b0e0e84589234a25a5d4d72f3594155.tar.xz
initscripts-b13728c31b0e0e84589234a25a5d4d72f3594155.zip
ftw? is slow.
-rw-r--r--src/kmodule.c50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/kmodule.c b/src/kmodule.c
index 5b0340ee..e2bcfb96 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,48 @@
#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 = mmap(0,sbuf.st_size,PROT_READ,MAP_SHARED,fd,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;