Browse Source

dracut-install: Globbing support for resolving "firmware:"

Implements #849
master
Daniel Molkentin 5 years ago committed by Daniel Molkentin
parent
commit
1a5845b45f
  1. 60
      install/dracut-install.c

60
install/dracut-install.c

@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <glob.h>
#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
@ -123,6 +124,7 @@ static inline void fts_closep(FTS **p) { @@ -123,6 +124,7 @@ static inline void fts_closep(FTS **p) {
}
#define _cleanup_fts_close_ _cleanup_(fts_closep)

#define _cleanup_globfree_ _cleanup_(globfree)


static size_t dir_len(char const *file)
@ -1328,8 +1330,33 @@ static int install_all(int argc, char **argv) @@ -1328,8 +1330,33 @@ static int install_all(int argc, char **argv)
return r;
}

static int install_firmware(struct kmod_module *mod)
static int install_firmware_fullpath(const char *fwpath)
{
const char *fw;
_cleanup_free_ char *fwpath_xz = NULL;
fw = fwpath;
struct stat sb;
int ret, r;
if (stat(fwpath, &sb) != 0) {
r = asprintf(&fwpath_xz, "%s.xz", fwpath);
if (r < 0) {
log_error("Out of memory!");
exit(EXIT_FAILURE);
}
if (stat(fwpath_xz, &sb) != 0) {
log_debug("stat(%s) != 0", fwpath);
return 1;
}
fw = fwpath_xz;
}
ret = dracut_install(fw, fw, false, false, true);
if (ret == 0) {
log_debug("dracut_install '%s' OK", fwpath);
}
return ret;
}

static int install_firmware(struct kmod_module *mod) {
struct kmod_list *l;
_cleanup_kmod_module_info_free_list_ struct kmod_list *list = NULL;
int ret;
@ -1354,8 +1381,6 @@ static int install_firmware(struct kmod_module *mod) @@ -1354,8 +1381,6 @@ static int install_firmware(struct kmod_module *mod)
ret = -1;
STRV_FOREACH(q, firmwaredirs) {
_cleanup_free_ char *fwpath = NULL;
_cleanup_free_ char *fwpath_xz = NULL;
const char *fw;
struct stat sb;
int r;

@ -1365,29 +1390,24 @@ static int install_firmware(struct kmod_module *mod) @@ -1365,29 +1390,24 @@ static int install_firmware(struct kmod_module *mod)
exit(EXIT_FAILURE);
}

fw = fwpath;
if (stat(fwpath, &sb) != 0) {
r = asprintf(&fwpath_xz, "%s.xz", fwpath);
if (r < 0) {
log_error("Out of memory!");
exit(EXIT_FAILURE);
}
if (stat(fwpath_xz, &sb) != 0) {
log_debug("stat(%s) != 0", fwpath);
continue;
}
fw = fwpath_xz;
if ((strstr(value, "*") != 0 || strstr(value, "?") != 0 || strstr(value, "[") != 0) && stat(fwpath, &sb) != 0) {
int i;
_cleanup_globfree_ glob_t globbuf;
glob(fwpath, 0, NULL, &globbuf);
for (i = 0; i < globbuf.gl_pathc; i++) {
install_firmware_fullpath(globbuf.gl_pathv[i]);
if (ret != 0) {
log_info("Possible missing firmware %s for kernel module %s", value, kmod_module_get_name(mod));
}

ret = dracut_install(fw, fw, false, false, true);
if (ret == 0)
log_debug("dracut_install '%s' OK", fwpath);
}

} else {
install_firmware_fullpath(fwpath);
if (ret != 0) {
log_info("Possible missing firmware %s for kernel module %s", value, kmod_module_get_name(mod));
}
}
}
}
return 0;
}


Loading…
Cancel
Save