gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / module-init-tools-moduledir.patch
1 This patch changes 'modprobe' & co. so they honor the 'LINUX_MODULE_DIRECTORY'
2 environment variable, rather than looking for modules exclusively in
3 /lib/modules.
4
5 Original patch by David Guibert, from Nixpkgs; adjusted to use
6 'LINUX_MODULE_DIRECTORY' rather than 'MODULE_DIR' as the variable name.
7
8 diff --git a/depmod.c b/depmod.c
9 index a1d2f8c..ff579c7 100644
10 --- a/depmod.c
11 +++ b/depmod.c
12 @@ -48,9 +48,6 @@
13
14 #include "testing.h"
15
16 -#ifndef MODULE_DIR
17 -#define MODULE_DIR "/lib/modules/"
18 -#endif
19
20 #ifndef MODULE_BUILTIN_KEY
21 #define MODULE_BUILTIN_KEY "built-in"
22 @@ -1516,6 +1513,7 @@ static int parse_config_file(const char *filename,
23 char *line;
24 unsigned int linenum = 0;
25 FILE *cfile;
26 + char *module_dir;
27
28 cfile = fopen(filename, "r");
29 if (!cfile) {
30 @@ -1525,6 +1523,10 @@ static int parse_config_file(const char *filename,
31 return 0;
32 }
33
34 + if((module_dir = getenv("LINUX_MODULE_DIRECTORY")) == NULL) {
35 + module_dir = "/lib/modules";
36 + }
37 +
38 while ((line = getline_wrapped(cfile, &linenum)) != NULL) {
39 char *ptr = line;
40 char *cmd, *modname;
41 @@ -1549,8 +1551,8 @@ static int parse_config_file(const char *filename,
42 0, *search);
43 continue;
44 }
45 - nofail_asprintf(&dirname, "%s%s%s/%s", basedir,
46 - MODULE_DIR, kernelversion, search_path);
47 + nofail_asprintf(&dirname, "%s%s/%s/%s", basedir,
48 + module_dir, kernelversion, search_path);
49 len = strlen(dirname);
50 *search = add_search(dirname, len, *search);
51 free(dirname);
52 @@ -1564,8 +1566,8 @@ static int parse_config_file(const char *filename,
53 if (!regex_match(kernelversion, (const char *)version))
54 continue;
55
56 - nofail_asprintf(&pathname, "%s%s%s/%s/%s.ko", basedir,
57 - MODULE_DIR, kernelversion, subdir, modname);
58 + nofail_asprintf(&pathname, "%s%s/%s/%s/%s.ko", basedir,
59 + module_dir, kernelversion, subdir, modname);
60
61 *overrides = add_override(pathname, *overrides);
62 free(pathname);
63 @@ -1737,6 +1739,7 @@ int main(int argc, char *argv[])
64 char *basedir = "", *dirname, *version;
65 char *system_map = NULL, *module_symvers = NULL;
66 int i;
67 + char *module_dir;
68 const char *config = NULL;
69
70 if (native_endianness() == 0)
71 @@ -1832,7 +1835,11 @@ int main(int argc, char *argv[])
72 if (optind == argc)
73 all = 1;
74
75 - nofail_asprintf(&dirname, "%s%s%s", basedir, MODULE_DIR, version);
76 + if((module_dir = getenv("LINUX_MODULE_DIRECTORY")) == NULL) {
77 + module_dir = "/lib/modules";
78 + }
79 +
80 + nofail_asprintf(&dirname, "%s%s/%s", basedir, module_dir, version);
81
82 if (maybe_all) {
83 if (!doing_stdout && !depfile_out_of_date(dirname))
84 @@ -1849,8 +1856,8 @@ int main(int argc, char *argv[])
85 char *dirname;
86 size_t len;
87
88 - nofail_asprintf(&dirname, "%s%s%s/updates", basedir,
89 - MODULE_DIR, version);
90 + nofail_asprintf(&dirname, "%s%s/%s/updates", basedir,
91 + module_dir, version);
92 len = strlen(dirname);
93 search = add_search(dirname, len, search);
94 }
95 diff --git a/modinfo.c b/modinfo.c
96 index 1dd8469..6a1865b 100644
97 --- a/modinfo.c
98 +++ b/modinfo.c
99 @@ -19,9 +19,6 @@
100 #include "zlibsupport.h"
101 #include "testing.h"
102
103 -#ifndef MODULE_DIR
104 -#define MODULE_DIR "/lib/modules"
105 -#endif
106
107 struct param
108 {
109 @@ -193,6 +190,11 @@ static struct elf_file *grab_module(const char *name,
110 struct utsname buf;
111 char *depname, *p, *moddir;
112 struct elf_file *module;
113 + char *module_dir;
114 +
115 + if((module_dir = getenv("LINUX_MODULE_DIRECTORY")) == NULL) {
116 + module_dir = "/lib/modules";
117 + }
118
119 if (strchr(name, '.') || strchr(name, '/')) {
120 module = grab_elf_file(name);
121 @@ -207,9 +209,9 @@ static struct elf_file *grab_module(const char *name,
122 kernel = buf.release;
123 }
124 if (strlen(basedir))
125 - nofail_asprintf(&moddir, "%s/%s/%s", basedir, MODULE_DIR, kernel);
126 + nofail_asprintf(&moddir, "%s/%s/%s", basedir, module_dir, kernel);
127 else
128 - nofail_asprintf(&moddir, "%s/%s", MODULE_DIR, kernel);
129 + nofail_asprintf(&moddir, "%s/%s", module_dir, kernel);
130
131 /* Search for it in modules.dep. */
132 nofail_asprintf(&depname, "%s/%s", moddir, "modules.dep");
133 diff --git a/modprobe.c b/modprobe.c
134 index 5464f45..cb57917 100644
135 --- a/modprobe.c
136 +++ b/modprobe.c
137 @@ -86,10 +86,6 @@ typedef enum
138
139 } modprobe_flags_t;
140
141 -#ifndef MODULE_DIR
142 -#define MODULE_DIR "/lib/modules"
143 -#endif
144 -
145 /**
146 * print_usage - output the prefered program usage
147 *
148 @@ -2136,6 +2132,7 @@ int main(int argc, char *argv[])
149 struct modprobe_conf conf = {};
150
151 recursion_depth = 0;
152 + char *module_dir = NULL;
153
154 /* Prepend options from environment. */
155 argv = merge_args(getenv("MODPROBE_OPTIONS"), argv, &argc);
156 @@ -2233,7 +2230,11 @@ int main(int argc, char *argv[])
157 if (argc < optind + 1 && !dump_config && !list_only)
158 print_usage(argv[0]);
159
160 - nofail_asprintf(&dirname, "%s%s/%s", basedir, MODULE_DIR, buf.release);
161 + if((module_dir = getenv("LINUX_MODULE_DIRECTORY")) == NULL) {
162 + module_dir = "/lib/modules";
163 + }
164 +
165 + nofail_asprintf(&dirname, "%s%s/%s", basedir, module_dir, buf.release);
166
167 /* Old-style -t xxx wildcard? Only with -l. */
168 if (list_only) {