62b2d5bcaa4cd32b4f3ac032e597471e3c2a27ec
2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <sys/syscall.h>
19 #include <sys/syscall.h>
20 #include <sys/types.h>
29 #include <sys/utsname.h>
31 #define DEF_MOD_PATH "/lib/modules/%s/%s.ko"
32 static int insmod(char *module
, const char *options
)
41 snprintf(path
, 256, DEF_MOD_PATH
, ver
.release
, module
);
44 fprintf(stderr
, "missing module %s\n", path
);
48 fd
= open(path
, O_RDONLY
);
50 fprintf(stderr
, "cannot open %s\n", path
);
54 data
= malloc(s
.st_size
);
55 if (read(fd
, data
, s
.st_size
) == s
.st_size
) {
56 ret
= syscall(__NR_init_module
, data
, s
.st_size
, options
);
58 fprintf(stderr
, "failed insert %s\n", module
);
60 fprintf(stderr
, "failed to read full module %s\n", path
);
69 /*static void rmmod(char *module)
71 syscall(__NR_delete_module, module, 0);
74 int main(int argc
, char **argv
)
77 int gl_flags
= GLOB_NOESCAPE
| GLOB_MARK
;
78 char *tmp
= malloc(256);
79 char *dir
= "/etc/modules.d/*";
84 syslog(0, "kmodloader: loading kernel modules from %s\n", dir
);
86 if (glob(dir
, gl_flags
, NULL
, &gl
) >= 0) {
89 for (j
= 0; j
< gl
.gl_pathc
; j
++) {
90 FILE *fp
= fopen(gl
.gl_pathv
[j
], "r");
93 fprintf(stderr
, "failed to open %s\n", gl
.gl_pathv
[j
]);
97 while (fgets(mod
, 64, fp
)) {
98 mod
[strlen(mod
) - 1] = '\0';