aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2007-09-10 17:37:00 +0000
committerBill Nottingham <notting@redhat.com>2007-09-10 17:37:00 +0000
commit9ab7101d8b6e7f2cec29b1a5643949c1186d27a9 (patch)
tree494308d2d21037622a3690146373e2cc7b01472d
parente9ecfbbf6d0aa3ead9e7a64417215ca1d9daf296 (diff)
downloadinitscripts-9ab7101d8b6e7f2cec29b1a5643949c1186d27a9.tar
initscripts-9ab7101d8b6e7f2cec29b1a5643949c1186d27a9.tar.gz
initscripts-9ab7101d8b6e7f2cec29b1a5643949c1186d27a9.tar.bz2
initscripts-9ab7101d8b6e7f2cec29b1a5643949c1186d27a9.tar.xz
initscripts-9ab7101d8b6e7f2cec29b1a5643949c1186d27a9.zip
use a better method for searching for modules (#270741)
-rw-r--r--src/kmodule.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/kmodule.c b/src/kmodule.c
index 494bd786..319e1523 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,35 +19,39 @@
#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;
- }
- return 0;
-}
-
-
int isAvailable(char *modulename)
{
struct utsname utsbuf;
- char path[512];
+ struct stat sbuf;
+ char path[512], mod_name[100];
+ char *buf;
+ int fd;
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;
+ 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);
+ if (!buf || buf == MAP_FAILED)
+ return 0;
+ close(fd);
+ snprintf(mod_name,100,"/%s.ko:", modulename);
+ if (strstr(buf, mod_name)) {
+ munmap(buf, sbuf.st_size);
+ return 1;
+ }
+ snprintf(mod_name,100,"/%s.ko.gz:", modulename);
+ if (strstr(buf, mod_name)) {
+ munmap(buf, sbuf.st_size);
+ return 1;
+ }
+ munmap(buf,sbuf.st_size);
}
return 0;
}