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 /src | |
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>
Diffstat (limited to 'src')
-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 |
3 files changed, 35 insertions, 6 deletions
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, }; |