@@ -23,17 +23,18 @@ diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c
2323index 96bc2eb6..96644151 100644
2424--- a/src/install/dracut-install.c
2525+++ b/src/install/dracut-install.c
26- @@ -83,9 +83,6 @@ FILE *logfile_f = NULL;
26+ @@ -91,10 +91,7 @@ FILE *logfile_f = NULL;
2727 static Hashmap *items = NULL;
2828 static Hashmap *items_failed = NULL;
2929 static Hashmap *modules_loaded = NULL;
3030- static Hashmap *modules_suppliers = NULL;
3131- static Hashmap *processed_suppliers = NULL;
32+ static Hashmap *processed_deps = NULL;
3233- static Hashmap *modalias_to_kmod = NULL;
33- static regex_t mod_filter_path ;
34- static regex_t mod_filter_nopath ;
35- static regex_t mod_filter_symbol ;
36- @@ -98 ,7 +95 ,7 @@ static bool arg_mod_filter_nosymbol = false;
34+ static Hashmap *add_dlopen_features = NULL ;
35+ static Hashmap *omit_dlopen_features = NULL ;
36+ static Hashmap *dlopen_features[2] = NULL ;
37+ @@ -110 ,7 +107 ,7 @@ static bool arg_mod_filter_nosymbol = false;
3738 static bool arg_mod_filter_noname = false;
3839
3940 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst);
@@ -42,7 +43,7 @@ index 96bc2eb6..96644151 100644
4243
4344 static void item_free(char *i)
4445 {
45- @@ -1571,164 +1568 ,7 @@ static bool check_module_path(const char *path)
46+ @@ -2148,168 +2145 ,7 @@ static bool check_module_path(const char *path)
4647 return true;
4748 }
4849
@@ -138,7 +139,7 @@ index 96bc2eb6..96644151 100644
138139- if (d) {
139140- size_t real_path_len = strlen(real_path);
140141- while ((dir = readdir(d)) != NULL) {
141- - if (strstr(dir->d_name, "supplier:platform ") != NULL) {
142+ - if (strstr(dir->d_name, "supplier:") != NULL) {
142143- if ((size_t)snprintf(real_path + real_path_len, sizeof(real_path) - real_path_len, "/%s/supplier",
143144- dir->d_name) < sizeof(real_path) - real_path_len) {
144145- char *real_supplier_path = realpath(real_path, NULL);
@@ -151,12 +152,16 @@ index 96bc2eb6..96644151 100644
151152- closedir(d);
152153- }
153154- strcat(node_path, "/.."); // Also find suppliers of parents
155+ - char *parent_path = realpath(node_path, NULL);
156+ - if (parent_path != NULL)
157+ - if (hashmap_put(suppliers, parent_path, parent_path) < 0)
158+ - free(parent_path);
154159- }
155160- }
156161-
157162- static void find_suppliers(struct kmod_ctx *ctx)
158163- {
159- - _cleanup_fts_close_ FTS *fts;
164+ - _cleanup_fts_close_ FTS *fts = NULL ;
160165- char *paths[] = { "/sys/devices/platform", NULL };
161166- fts = fts_open(paths, FTS_NOSTAT | FTS_PHYSICAL, NULL);
162167-
@@ -208,7 +213,7 @@ index 96bc2eb6..96644151 100644
208213 {
209214 const char *path = NULL;
210215 const char *name = NULL;
211- @@ -1762,13 +1602,13 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
216+ @@ -2343,21 +2179,21 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
212217 log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]);
213218 install_firmware(mod);
214219 modlist = kmod_module_get_dependencies(mod);
@@ -225,7 +230,16 @@ index 96bc2eb6..96644151 100644
225230 *err = *err ? : r;
226231 }
227232 }
228- @@ -1786,7 +1626,7 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
233+ #ifdef CONFIG_WEAKDEP
234+ if (*err == 0) {
235+ *err = kmod_module_get_weakdeps(mod, &modweak);
236+ if (*err == 0)
237+ - *err = install_dependent_modules(ctx, modweak, NULL);
238+ + *err = install_dependent_modules(modweak);
239+ }
240+ #endif
241+ } else {
242+ @@ -2367,7 +2203,7 @@ static int install_dependent_module(struct kmod_ctx *ctx, struct kmod_module *mo
229243 return 0;
230244 }
231245
@@ -234,7 +248,7 @@ index 96bc2eb6..96644151 100644
234248 {
235249 struct kmod_list *itr = NULL;
236250 int ret = 0;
237- @@ -1794 ,44 +1634 ,14 @@ static int install_dependent_modules(struct kmod_ctx *ctx, struct kmod_list *mod
251+ @@ -2375 ,44 +2211 ,14 @@ static int install_dependent_modules(struct kmod_ctx *ctx, struct kmod_list *mod
238252 kmod_list_foreach(itr, modlist) {
239253 _cleanup_kmod_module_unref_ struct kmod_module *mod = NULL;
240254 mod = kmod_module_get_module(itr);
@@ -255,20 +269,20 @@ index 96bc2eb6..96644151 100644
255269- _cleanup_destroy_hashmap_ Hashmap *modules = hashmap_new(string_hash_func, string_compare_func);
256270- find_modules_from_sysfs_node(ctx, supplier_path, modules);
257271-
258- - _cleanup_destroy_hashmap_ Hashmap *suppliers = hashmap_new(string_hash_func, string_compare_func);
259- - find_suppliers_for_sys_node(suppliers, supplier_path, strlen(supplier_path));
260- -
261272- if (!hashmap_isempty(modules)) { // Supplier is a module
262273- const char *module;
263274- Iterator j;
264275- HASHMAP_FOREACH(module, modules, j) {
265276- _cleanup_kmod_module_unref_ struct kmod_module *mod = NULL;
266277- if (!kmod_module_new_from_name(ctx, module, &mod)) {
278+ - Hashmap *suppliers = find_suppliers_paths_for_module(kmod_module_get_name(mod));
267279- if (install_dependent_module(ctx, mod, suppliers, &ret))
268280- return -1;
269281- }
270282- }
271283- } else { // Supplier is builtin
284+ - _cleanup_destroy_hashmap_ Hashmap *suppliers = hashmap_new(string_hash_func, string_compare_func);
285+ - find_suppliers_for_sys_node(suppliers, supplier_path, strlen(supplier_path));
272286- install_dependent_modules(ctx, NULL, suppliers);
273287- }
274288- }
@@ -281,7 +295,7 @@ index 96bc2eb6..96644151 100644
281295 {
282296 int ret = 0;
283297 _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
284- @@ -1884,16 +1694,15 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
298+ @@ -2465,24 +2271,23 @@ static int install_module(struct kmod_ctx *ctx, struct kmod_module *mod)
285299 }
286300 install_firmware(mod);
287301
@@ -301,7 +315,16 @@ index 96bc2eb6..96644151 100644
301315 ret = ret ? : r;
302316 }
303317 }
304- @@ -2012,9 +1821,6 @@ static int install_modules(int argc, char **argv)
318+ #ifdef CONFIG_WEAKDEP
319+ if (ret == 0) {
320+ ret = kmod_module_get_weakdeps(mod, &modweak);
321+ if (ret == 0)
322+ - ret = install_dependent_modules(ctx, modweak, NULL);
323+ + ret = install_dependent_modules(modweak);
324+ }
325+ #endif
326+
327+ @@ -2593,9 +2398,6 @@ static int install_modules(int argc, char **argv)
305328 if (p != NULL)
306329 kerneldirlen = p - abskpath;
307330
@@ -311,7 +334,7 @@ index 96bc2eb6..96644151 100644
311334 if (arg_hostonly) {
312335 char *modalias_file;
313336 modalias_file = getenv("DRACUT_KERNEL_MODALIASES");
314- @@ -2102 ,7 +1908 ,7 @@ static int install_modules(int argc, char **argv)
337+ @@ -2683 ,7 +2485 ,7 @@ static int install_modules(int argc, char **argv)
315338 }
316339 kmod_list_foreach(itr, modlist) {
317340 mod = kmod_module_get_module(itr);
@@ -320,7 +343,7 @@ index 96bc2eb6..96644151 100644
320343 kmod_module_unref(mod);
321344 if ((r < 0) && !arg_optional) {
322345 if (!arg_silent)
323- @@ -2181 ,7 +1987 ,7 @@ static int install_modules(int argc, char **argv)
346+ @@ -2763 ,7 +2565 ,7 @@ static int install_modules(int argc, char **argv)
324347 }
325348 kmod_list_foreach(itr, modlist) {
326349 mod = kmod_module_get_module(itr);
@@ -329,7 +352,7 @@ index 96bc2eb6..96644151 100644
329352 kmod_module_unref(mod);
330353 if ((r < 0) && !arg_optional) {
331354 if (!arg_silent)
332- @@ -2232 ,7 +2038 ,7 @@ static int install_modules(int argc, char **argv)
355+ @@ -2813 ,7 +2615 ,7 @@ static int install_modules(int argc, char **argv)
333356 }
334357 kmod_list_foreach(itr, modlist) {
335358 mod = kmod_module_get_module(itr);
@@ -338,19 +361,24 @@ index 96bc2eb6..96644151 100644
338361 kmod_module_unref(mod);
339362 if ((r < 0) && !arg_optional) {
340363 if (!arg_silent)
341- @@ -2333,10 +2139,8 @@ int main(int argc, char **argv)
364+ @@ -3006,15 +2808,13 @@ int main(int argc, char **argv)
342365
343366 items = hashmap_new(string_hash_func, string_compare_func);
344367 items_failed = hashmap_new(string_hash_func, string_compare_func);
345368- processed_suppliers = hashmap_new(string_hash_func, string_compare_func);
369+ processed_deps = hashmap_new(string_hash_func, string_compare_func);
346370- modalias_to_kmod = hashmap_new(string_hash_func, string_compare_func);
347371
348- - if (!items || !items_failed || !processed_suppliers || !modules_loaded) {
349- + if (!items || !items_failed || !modules_loaded) {
372+ dlopen_features[0] = add_dlopen_features = hashmap_new(string_hash_func, string_compare_func);
373+ dlopen_features[1] = omit_dlopen_features = hashmap_new(string_hash_func, string_compare_func);
374+
375+ - if (!items || !items_failed || !processed_suppliers || !modules_loaded ||
376+ + if (!items || !items_failed || !modules_loaded ||
377+ !processed_deps || !add_dlopen_features || !omit_dlopen_features) {
350378 log_error("Out of memory");
351379 r = EXIT_FAILURE;
352380 goto finish1;
353- @@ -2397,28 +2201,9 @@ finish2:
381+ @@ -3082,47 +2882,10 @@ finish2:
354382 while ((i = hashmap_steal_first(items_failed)))
355383 item_free(i);
356384
@@ -365,6 +393,24 @@ index 96bc2eb6..96644151 100644
365393- while ((i = hashmap_steal_first(processed_suppliers)))
366394- item_free(i);
367395-
396+ - while ((i = hashmap_steal_first(processed_deps)))
397+ - item_free(i);
398+ -
399+ - for (size_t j = 0; j < 2; j++) {
400+ - char ***array;
401+ - Iterator it;
402+ -
403+ - HASHMAP_FOREACH(array, dlopen_features[j], it) {
404+ - strv_free(*array);
405+ - free(array);
406+ - }
407+ -
408+ - while ((i = hashmap_steal_first_key(dlopen_features[j])))
409+ - item_free(i);
410+ -
411+ - hashmap_free(dlopen_features[j]);
412+ - }
413+ -
368414- /*
369415- * Note: modalias_to_kmod's values are freed implicitly by the kmod context destruction
370416- * in kmod_unref().
@@ -375,6 +421,7 @@ index 96bc2eb6..96644151 100644
375421 hashmap_free(modules_loaded);
376422- hashmap_free(modules_suppliers);
377423- hashmap_free(processed_suppliers);
424+ hashmap_free(processed_deps);
378425- hashmap_free(modalias_to_kmod);
379426
380427 if (arg_mod_filter_path)
0 commit comments