kmod: add patch to allow searching for modules in several directories
This commit is contained in:
parent
1047ed49d9
commit
30c9aa2698
|
@ -1,30 +1,37 @@
|
||||||
{ stdenv, fetchurl, xz, zlib, pkgconfig, libxslt }:
|
{ stdenv, lib, fetchurl, autoreconfHook, xz, zlib, pkgconfig, libxslt }:
|
||||||
|
|
||||||
let
|
let
|
||||||
systems = [ "/run/current-system/kernel-modules" "/run/booted-system/kernel-modules" "" ];
|
systems = [ "current-system" "booted-system" ];
|
||||||
modulesDirs = lib.concatMapStringsSep ":" (x: "${x}/lib/modules") systems;
|
modulesDirs = lib.concatMapStringsSep ":" (x: "/run/${x}/kernel-modules/lib/modules") systems;
|
||||||
|
|
||||||
in stdenv.mkDerivation rec {
|
in stdenv.mkDerivation rec {
|
||||||
name = "kmod-${version}";
|
name = "kmod-${version}";
|
||||||
version = "23";
|
version = "22";
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = "mirror://kernel/linux/utils/kernel/kmod/${name}.tar.xz";
|
url = "mirror://kernel/linux/utils/kernel/kmod/${name}.tar.xz";
|
||||||
sha256 = "0mc12sx06p8il1ym3hdmgxxb37apn9yv7xij26gddjdfkx8xa0yk";
|
sha256 = "0mc12sx06p8il1ym3hdmgxxb37apn9yv7xij26gddjdfkx8xa0yk";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ pkgconfig libxslt xz /* zlib */ ];
|
nativeBuildInputs = [ autoreconfHook pkgconfig libxslt ];
|
||||||
|
buildInputs = [ xz /* zlib */ ];
|
||||||
|
|
||||||
configureFlags = [ "--sysconfdir=/etc" "--with-xz" /* "--with-zlib" */ ];
|
configureFlags = [
|
||||||
|
"--sysconfdir=/etc"
|
||||||
|
"--with-xz"
|
||||||
|
"--with-modulesdirs=${modulesDirs}"
|
||||||
|
# "--with-zlib"
|
||||||
|
];
|
||||||
|
|
||||||
patches = [ ./module-dir.patch ];
|
patches = [ ./module-dir.patch ];
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
ln -s kmod $out/bin/lsmod
|
for prog in rmmod insmod lsmod modinfo modprobe depmod; do
|
||||||
mkdir -p $out/sbin
|
ln -sv $out/bin/kmod $out/bin/$prog
|
||||||
for prog in rmmod insmod modinfo modprobe depmod; do
|
|
||||||
ln -sv $out/bin/kmod $out/sbin/$prog
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Backwards compatibility
|
||||||
|
ln -s bin $out/sbin
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
|
|
|
@ -1,7 +1,46 @@
|
||||||
diff -ru -x '*~' kmod-17-orig/libkmod/libkmod.c kmod-17/libkmod/libkmod.c
|
diff --git a/Makefile.am b/Makefile.am
|
||||||
--- kmod-17-orig/libkmod/libkmod.c 2014-04-01 12:40:37.161940089 +0200
|
index d4eeb7e..5c9f603 100644
|
||||||
+++ kmod-17/libkmod/libkmod.c 2014-04-17 13:47:15.871441987 +0200
|
--- a/Makefile.am
|
||||||
@@ -201,7 +201,7 @@
|
+++ b/Makefile.am
|
||||||
|
@@ -19,6 +19,7 @@ AM_CPPFLAGS = \
|
||||||
|
-include $(top_builddir)/config.h \
|
||||||
|
-I$(top_srcdir) \
|
||||||
|
-DSYSCONFDIR=\""$(sysconfdir)"\" \
|
||||||
|
+ -DMODULESDIRS=\""$(shell echo $(modulesdirs) | $(SED) 's|:|\\",\\"|g')"\" \
|
||||||
|
${zlib_CFLAGS}
|
||||||
|
|
||||||
|
AM_CFLAGS = $(OUR_CFLAGS)
|
||||||
|
diff --git a/configure.ac b/configure.ac
|
||||||
|
index 23510c8..66490cf 100644
|
||||||
|
--- a/configure.ac
|
||||||
|
+++ b/configure.ac
|
||||||
|
@@ -202,6 +202,12 @@ GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
|
||||||
|
], [
|
||||||
|
AM_CONDITIONAL([ENABLE_GTK_DOC], false)])
|
||||||
|
|
||||||
|
+AC_ARG_WITH([modulesdirs],
|
||||||
|
+ AS_HELP_STRING([--with-modulesdirs=DIRS], [Kernel modules directories, separated by :]),
|
||||||
|
+ [],
|
||||||
|
+ [with_modulesdirs=/lib/modules])
|
||||||
|
+AC_SUBST([modulesdirs], [$with_modulesdirs])
|
||||||
|
+
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
# Default CFLAGS and LDFLAGS
|
||||||
|
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
|
||||||
|
index 69fe431..d37da32 100644
|
||||||
|
--- a/libkmod/libkmod.c
|
||||||
|
+++ b/libkmod/libkmod.c
|
||||||
|
@@ -206,12 +206,15 @@ static int log_priority(const char *priority)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
-static const char *dirname_default_prefix = "/lib/modules";
|
||||||
|
+static const char *dirname_default_prefixes[] = {
|
||||||
|
+ MODULESDIRS,
|
||||||
|
+ NULL
|
||||||
|
+};
|
||||||
|
|
||||||
static char *get_kernel_release(const char *dirname)
|
static char *get_kernel_release(const char *dirname)
|
||||||
{
|
{
|
||||||
struct utsname u;
|
struct utsname u;
|
||||||
|
@ -10,51 +49,109 @@ diff -ru -x '*~' kmod-17-orig/libkmod/libkmod.c kmod-17/libkmod/libkmod.c
|
||||||
|
|
||||||
if (dirname != NULL)
|
if (dirname != NULL)
|
||||||
return path_make_absolute_cwd(dirname);
|
return path_make_absolute_cwd(dirname);
|
||||||
@@ -209,7 +209,10 @@
|
@@ -219,8 +222,42 @@ static char *get_kernel_release(const char *dirname)
|
||||||
if (uname(&u) < 0)
|
if (uname(&u) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
- if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
|
- if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
|
||||||
+ if ((dirname_prefix = getenv("MODULE_DIR")) == NULL)
|
- return NULL;
|
||||||
+ dirname_prefix = dirname_default_prefix;
|
+ if ((dirname_prefix = getenv("MODULE_DIR")) != NULL) {
|
||||||
|
+ if(asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0)
|
||||||
|
+ return NULL;
|
||||||
|
+ } else {
|
||||||
|
+ size_t i;
|
||||||
|
+ char buf[PATH_MAX];
|
||||||
+
|
+
|
||||||
+ if (asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0)
|
+ for (i = 0; dirname_default_prefixes[i] != NULL; i++) {
|
||||||
return NULL;
|
+ int plen;
|
||||||
|
+ struct stat dirstat;
|
||||||
|
+
|
||||||
|
+ plen = snprintf(buf, sizeof(buf), "%s/%s", dirname_default_prefixes[i], u.release);
|
||||||
|
+ if (plen < 0)
|
||||||
|
+ return NULL;
|
||||||
|
+ else if (plen >= PATH_MAX)
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
+ if (dirname_default_prefixes[i + 1] != NULL) {
|
||||||
|
+ if (stat(buf, &dirstat) < 0) {
|
||||||
|
+ if (errno == ENOENT)
|
||||||
|
+ continue;
|
||||||
|
+ else
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (!S_ISDIR(dirstat.st_mode))
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ p = malloc(plen + 1);
|
||||||
|
+ if (p == NULL)
|
||||||
|
+ return NULL;
|
||||||
|
+ memcpy(p, buf, plen + 1);
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
diff -ru -x '*~' kmod-17-orig/tools/static-nodes.c kmod-17/tools/static-nodes.c
|
}
|
||||||
--- kmod-17-orig/tools/static-nodes.c 2013-12-17 22:05:42.159047316 +0100
|
diff --git a/tools/static-nodes.c b/tools/static-nodes.c
|
||||||
+++ kmod-17/tools/static-nodes.c 2014-04-17 13:51:17.945974320 +0200
|
index 8d2356d..2ed306d 100644
|
||||||
@@ -159,6 +159,7 @@
|
--- a/tools/static-nodes.c
|
||||||
|
+++ b/tools/static-nodes.c
|
||||||
|
@@ -29,10 +29,11 @@
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
-#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#include <shared/util.h>
|
||||||
|
|
||||||
|
+#include <libkmod/libkmod.h>
|
||||||
|
+
|
||||||
|
#include "kmod.h"
|
||||||
|
|
||||||
|
struct static_nodes_format {
|
||||||
|
@@ -154,8 +155,8 @@ static void help(void)
|
||||||
|
|
||||||
|
static int do_static_nodes(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
- struct utsname kernel;
|
||||||
|
char modules[PATH_MAX], buf[4096];
|
||||||
|
+ struct kmod_ctx *ctx;
|
||||||
|
const char *output = "/dev/stdout";
|
||||||
FILE *in = NULL, *out = NULL;
|
FILE *in = NULL, *out = NULL;
|
||||||
const struct static_nodes_format *format = &static_nodes_format_human;
|
const struct static_nodes_format *format = &static_nodes_format_human;
|
||||||
int r, ret = EXIT_SUCCESS;
|
@@ -206,22 +207,25 @@ static int do_static_nodes(int argc, char *argv[])
|
||||||
+ char *dirname_prefix;
|
}
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
int c, idx = 0, valid;
|
|
||||||
@@ -211,16 +212,19 @@
|
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- if (uname(&kernel) < 0) {
|
||||||
|
- fputs("Error: uname failed!\n", stderr);
|
||||||
|
+ ctx = kmod_new(NULL, NULL);
|
||||||
|
+ if (ctx == NULL) {
|
||||||
|
+ fprintf(stderr, "Error: failed to create kmod context\n");
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
-
|
||||||
- snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
|
- snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
|
||||||
+ if ((dirname_prefix = getenv("MODULE_DIR")) == NULL)
|
+ if (snprintf(modules, sizeof(modules), "%s/modules.devname", kmod_get_dirname(ctx)) < 0) {
|
||||||
+ dirname_prefix = "/lib/modules";
|
+ fprintf(stderr, "Error: path to modules.devname is too long\n");
|
||||||
+
|
+ ret = EXIT_FAILURE;
|
||||||
+ snprintf(modules, sizeof(modules), "%s/%s/modules.devname", dirname_prefix, kernel.release);
|
+ goto finish;
|
||||||
|
+ }
|
||||||
|
+ kmod_unref(ctx);
|
||||||
in = fopen(modules, "re");
|
in = fopen(modules, "re");
|
||||||
if (in == NULL) {
|
if (in == NULL) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
- fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
|
- fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
|
||||||
- kernel.release);
|
- kernel.release);
|
||||||
+ fprintf(stderr, "Warning: %s/%s/modules.devname not found - ignoring\n",
|
+ fprintf(stderr, "Warning: %s not found - ignoring\n", modules);
|
||||||
+ dirname_prefix, kernel.release);
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
- fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
|
- fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
|
||||||
- kernel.release);
|
- kernel.release);
|
||||||
+ fprintf(stderr, "Error: could not open %s/%s/modules.devname - %m\n",
|
+ fprintf(stderr, "Error: could not open %s - %m\n", modules);
|
||||||
+ dirname_prefix, kernel.release);
|
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
Loading…
Reference in New Issue