vuls: init at 0.27.0 (#348530)
[NixPkgs.git] / pkgs / os-specific / linux / kmod / module-dir.patch
blobf7432e3756e9bafe3e6736ca5df5d862ea18e8aa
1 diff --git a/Makefile.am b/Makefile.am
2 index d4eeb7e..5c9f603 100644
3 --- a/Makefile.am
4 +++ b/Makefile.am
5 @@ -19,6 +19,7 @@ AM_CPPFLAGS = \
6 -include $(top_builddir)/config.h \
7 -I$(top_srcdir) \
8 -DSYSCONFDIR=\""$(sysconfdir)"\" \
9 + -DMODULESDIRS=\""$(shell echo $(modulesdirs) | $(SED) 's|:|\\",\\"|g')"\" \
10 ${zlib_CFLAGS}
12 AM_CFLAGS = $(OUR_CFLAGS)
13 diff --git a/configure.ac b/configure.ac
14 index 23510c8..66490cf 100644
15 --- a/configure.ac
16 +++ b/configure.ac
17 @@ -202,6 +202,12 @@ GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
18 ], [
19 AM_CONDITIONAL([ENABLE_GTK_DOC], false)])
21 +AC_ARG_WITH([modulesdirs],
22 + AS_HELP_STRING([--with-modulesdirs=DIRS], [Kernel modules directories, separated by :]),
23 + [],
24 + [with_modulesdirs=/lib/modules])
25 +AC_SUBST([modulesdirs], [$with_modulesdirs])
28 #####################################################################
29 # Default CFLAGS and LDFLAGS
30 diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
31 index 69fe431..d37da32 100644
32 --- a/libkmod/libkmod.c
33 +++ b/libkmod/libkmod.c
34 @@ -206,12 +206,15 @@ static int log_priority(const char *priority)
35 return 0;
38 -static const char *dirname_default_prefix = "/lib/modules";
39 +static const char *dirname_default_prefixes[] = {
40 + MODULESDIRS,
41 + NULL
42 +};
44 static char *get_kernel_release(const char *dirname)
46 struct utsname u;
47 - char *p;
48 + char *p, *dirname_prefix;
50 if (dirname != NULL)
51 return path_make_absolute_cwd(dirname);
52 @@ -219,8 +222,42 @@ static char *get_kernel_release(const char *dirname)
53 if (uname(&u) < 0)
54 return NULL;
56 - if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
57 - return NULL;
58 + if ((dirname_prefix = getenv("MODULE_DIR")) != NULL) {
59 + if(asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0)
60 + return NULL;
61 + } else {
62 + size_t i;
63 + char buf[PATH_MAX];
65 + for (i = 0; dirname_default_prefixes[i] != NULL; i++) {
66 + int plen;
67 + struct stat dirstat;
69 + plen = snprintf(buf, sizeof(buf), "%s/%s", dirname_default_prefixes[i], u.release);
70 + if (plen < 0)
71 + return NULL;
72 + else if (plen >= PATH_MAX)
73 + continue;
75 + if (dirname_default_prefixes[i + 1] != NULL) {
76 + if (stat(buf, &dirstat) < 0) {
77 + if (errno == ENOENT)
78 + continue;
79 + else
80 + return NULL;
81 + }
83 + if (!S_ISDIR(dirstat.st_mode))
84 + continue;
85 + }
87 + p = malloc(plen + 1);
88 + if (p == NULL)
89 + return NULL;
90 + memcpy(p, buf, plen + 1);
91 + break;
92 + }
93 + }
95 return p;
97 diff --git a/tools/static-nodes.c b/tools/static-nodes.c
98 index 8d2356d..2ed306d 100644
99 --- a/tools/static-nodes.c
100 +++ b/tools/static-nodes.c
101 @@ -29,10 +29,11 @@
102 #include <unistd.h>
103 #include <sys/stat.h>
104 #include <sys/types.h>
105 -#include <sys/utsname.h>
107 #include <shared/util.h>
109 +#include <libkmod/libkmod.h>
111 #include "kmod.h"
113 struct static_nodes_format {
114 @@ -154,8 +155,8 @@ static void help(void)
116 static int do_static_nodes(int argc, char *argv[])
118 - struct utsname kernel;
119 char modules[PATH_MAX], buf[4096];
120 + struct kmod_ctx *ctx;
121 const char *output = "/dev/stdout";
122 FILE *in = NULL, *out = NULL;
123 const struct static_nodes_format *format = &static_nodes_format_human;
124 @@ -206,22 +207,25 @@ static int do_static_nodes(int argc, char *argv[])
128 - if (uname(&kernel) < 0) {
129 - fputs("Error: uname failed!\n", stderr);
130 + ctx = kmod_new(NULL, NULL);
131 + if (ctx == NULL) {
132 + fprintf(stderr, "Error: failed to create kmod context\n");
133 ret = EXIT_FAILURE;
134 goto finish;
137 - snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
138 + if (snprintf(modules, sizeof(modules), "%s/modules.devname", kmod_get_dirname(ctx)) < 0) {
139 + fprintf(stderr, "Error: path to modules.devname is too long\n");
140 + ret = EXIT_FAILURE;
141 + goto finish;
143 + kmod_unref(ctx);
144 in = fopen(modules, "re");
145 if (in == NULL) {
146 if (errno == ENOENT) {
147 - fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
148 - kernel.release);
149 + fprintf(stderr, "Warning: %s not found - ignoring\n", modules);
150 ret = EXIT_SUCCESS;
151 } else {
152 - fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
153 - kernel.release);
154 + fprintf(stderr, "Error: could not open %s - %m\n", modules);
155 ret = EXIT_FAILURE;
157 goto finish;