diff options
author | Richard Yao <ryao@gentoo.org> | 2012-11-19 11:49:42 -0500 |
---|---|---|
committer | Richard Yao <ryao@cs.stonybrook.edu> | 2012-11-23 01:55:28 -0500 |
commit | c4d1ce9b754e6eed60d2625cc4fff224898aa5d5 (patch) | |
tree | b49d37e4dd0fc0c69686abf5c18ed8eb11369011 | |
parent | 135d61df6f66d0c0e67aec62f76ee7f2a409a3ce (diff) |
Use libkmod only when requested
We support module loading through modprobe when libkmod is neither
available nor wanted.
Signed-off-by: Richard Yao <ryao@gentoo.org>
-rw-r--r-- | configure.ac | 29 | ||||
-rw-r--r-- | src/test/Makefile.am | 5 | ||||
-rw-r--r-- | src/udev/Makefile.am | 15 | ||||
-rw-r--r-- | src/udev/udev-builtin-kmod.c | 21 |
4 files changed, 63 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index 822a53044b..489733c94f 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,6 @@ if test -z "$GPERF" ; then AC_MSG_ERROR([*** gperf not found]) fi -PKG_CHECK_MODULES(KMOD, [libkmod >= 5]) PKG_CHECK_MODULES(BLKID,[blkid >= 2.20]) # Checks for header files. @@ -278,6 +277,34 @@ AC_SUBST([udevlibexecdir], [${with_rootlibdir}/udev]) # ------------------------------------------------------------------------------ +AC_ARG_ENABLE([libkmod], [AS_HELP_STRING([--enable-libkmod], [Enable module loading through kmod @<:@default=disabled@:>@])], [], [with_libkmod=no]) + +LIBKMOD= +AS_IF([test "x$with_libkmod" != xno], + [AC_CHECK_LIB([kmod], [main], + [PKG_CHECK_MODULES(KMOD, [libkmod >= 5]) + AC_SUBST([LIBKMOD], ["-lkmod"]) + AC_DEFINE([HAVE_LIBKMOD], [1], + [Define if you have libkmod]) + ], + [AC_MSG_FAILURE( + [--with-libkmod was given, but test for kmod failed])], + [-lkmod])]) + +AM_CONDITIONAL([HAVE_LIBKMOD], [test "$with_kmod" = "yes"]) + +# ------------------------------------------------------------------------------ + +AC_ARG_WITH([modprobe], + [AS_HELP_STRING([--with-modprobe=modprobe], + [specify location of modprobe when -- @<:@default=$sbindir/modprobe@:>@])], + [], + [with_modprobe="${sbindir}/modprobe"]) + +AC_SUBST([MODPROBE], ["${with_modprobe}"]) + +# ------------------------------------------------------------------------------ + AC_CONFIG_FILES([Makefile docs/Makefile docs/gudev/Makefile diff --git a/src/test/Makefile.am b/src/test/Makefile.am index d50200d821..642e7c2efe 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -28,9 +28,12 @@ test_udev_LDADD = \ $(top_builddir)/src/libudev/libudev-private.la \ $(top_builddir)/src/udev/libudev-core.la \ $(BLKID_LIBS) \ - $(KMOD_LIBS) \ $(SELINUX_LIBS) +if HAVE_LIBKMOD +test_udev_LDADD += $(KMOD_LIBS) +endif + test_udev_CPPFLAGS = \ -I $(top_srcdir)/src/udev \ $(AM_CPPFLAGS) diff --git a/src/udev/Makefile.am b/src/udev/Makefile.am index ab1322a1a2..7ceb31951a 100644 --- a/src/udev/Makefile.am +++ b/src/udev/Makefile.am @@ -6,6 +6,7 @@ udevhomedir = $(udevlibexecdir) AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ + -DMODPROBE=\"$(MODPROBE)\" \ -DROOTPREFIX=\"$(rootprefix)\" \ -DUDEVLIBEXECDIR=\"$(udevlibexecdir)\" \ -I $(top_srcdir)/src/libudev @@ -101,13 +102,19 @@ include_HEADERS = \ libudev_core_la_CFLAGS = \ $(AM_CFLAGS) \ - $(BLKID_CFLAGS) \ - $(KMOD_CFLAGS) + $(BLKID_CFLAGS) + +if HAVE_LIBKMOD +libudev_core_la_CFLAGS += $(KMOD_CFLAGS) +endif libudev_core_la_LIBADD = \ $(top_builddir)/src/libudev/libudev-private.la \ - $(BLKID_LIBS) \ - $(KMOD_LIBS) + $(BLKID_LIBS) + +if HAVE_LIBKMOD +libudev_core_la_LIBADD += $(KMOD_LIBS) +endif if HAVE_ACL libudev_core_la_SOURCES += \ diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index 17aca2944d..89c7ab0b77 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -27,14 +27,19 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/wait.h> + +#ifdef HAVE_LIBKMOD #include <libkmod.h> +#endif #include "udev.h" +#include "util.h" static struct kmod_ctx *ctx; -static int load_module(struct udev *udev, const char *alias) +static int load_module(struct udev *udev, char *const alias) { +#ifdef HAVE_LIBKMOD struct kmod_list *list = NULL; struct kmod_list *l; int err; @@ -62,6 +67,10 @@ static int load_module(struct udev *udev, const char *alias) kmod_module_unref_list(list); return err; +#else + char * const argv[] = { "-bq", alias, 0 }; + return execute_command(MODPROBE, argv); +#endif } static void udev_kmod_log(void *data, int priority, const char *file, int line, @@ -75,8 +84,10 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te struct udev *udev = udev_device_get_udev(dev); int i; +#ifdef HAVE_LIBKMOD if (!ctx) return 0; +#endif if (argc < 3 || strcmp(argv[1], "load")) { log_error("expect: %s load <module>\n", argv[0]); @@ -94,6 +105,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te /* called at udev startup and reload */ static int builtin_kmod_init(struct udev *udev) { +#ifdef HAVE_LIBKMOD if (ctx) return 0; @@ -104,16 +116,20 @@ static int builtin_kmod_init(struct udev *udev) log_debug("load module index\n"); kmod_set_log_fn(ctx, udev_kmod_log, udev); kmod_load_resources(ctx); +#endif return 0; } /* called on udev shutdown and reload request */ static void builtin_kmod_exit(struct udev *udev) { +#ifdef HAVE_LIBKMOD log_debug("unload module index\n"); ctx = kmod_unref(ctx); +#endif } +#ifdef HAVE_LIBKMOD /* called every couple of seconds during event activity; 'true' if config has changed */ static bool builtin_kmod_validate(struct udev *udev) { @@ -122,13 +138,16 @@ static bool builtin_kmod_validate(struct udev *udev) return false; return (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK); } +#endif const struct udev_builtin udev_builtin_kmod = { .name = "kmod", .cmd = builtin_kmod, .init = builtin_kmod_init, .exit = builtin_kmod_exit, +#ifdef HAVE_LIBKMOD .validate = builtin_kmod_validate, +#endif .help = "kernel module loader", .run_once = false, }; |