src/udev/udev-builtin-kmod.c: remove the modprobe alt to kmod code

This commit is contained in:
Anthony G. Basile 2015-02-11 18:06:47 -05:00
parent 158c3f34cf
commit 79bf63bcff
9 changed files with 27 additions and 96 deletions

1
LEGACY
View File

@ -5,4 +5,5 @@ v1.X - preserves the old userland firmware loading code
v2.X - preserves the older rules generator code
- preserves the old static nodes created from modules code
- preserves the the old modprobe alt to kmod code

View File

@ -299,40 +299,20 @@ AM_CONDITIONAL(ENABLE_MANPAGES, [test "x$have_manpages" = "xyes"])
AC_SUBST(XSLTPROC_FLAGS)
# ------------------------------------------------------------------------------
AC_ARG_ENABLE(modules, [AS_HELP_STRING([--disable-modules], [Disable loadable module support @<:@default=enabled@:>@])], [], [enable_modules=yes])
AC_ARG_ENABLE(libkmod, [AS_HELP_STRING([--enable-libkmod], [Enable module loading through kmod @<:@default=disabled@:>@])], [], [enable_libkmod=no])
if test "x${enable_modules}" = xyes; then
AC_DEFINE([HAVE_MODULES], [1], [Define if we support loading modules])
AS_IF([test "x${enable_libkmod}" = xyes],
[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(
[--enable-libkmod was given, but test for kmod failed])],
[-lkmod])])
have_kmod=no
AC_ARG_ENABLE(kmod, AS_HELP_STRING([--disable-kmod], [disable loadable modules support]))
if test "x$enable_kmod" != "xno"; then
PKG_CHECK_EXISTS([ libkmod ], have_kmod=yes, have_kmod=no)
if test "x$have_kmod" = "xyes"; then
PKG_CHECK_MODULES(KMOD, [ libkmod >= 15 ],
[AC_DEFINE(HAVE_KMOD, 1, [Define if kmod is available])],
AC_MSG_ERROR([*** kmod version >= 15 not found]))
fi
if test "x$have_kmod" = xno -a "x$enable_kmod" = xyes; then
AC_MSG_ERROR([*** kmod support requested, but libraries not found])
fi
fi
AM_CONDITIONAL([HAVE_MODULES], [test "x${enable_modules}" = xyes])
AM_CONDITIONAL([HAVE_LIBKMOD], [test "x${enable_libkmod}" = xyes])
# ------------------------------------------------------------------------------
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}"])
AM_CONDITIONAL(HAVE_KMOD, [test "$have_kmod" = "yes"])
# ------------------------------------------------------------------------------

View File

@ -1,13 +0,0 @@
# do not edit this file, it will be overwritten on update
ACTION=="remove", GOTO="drivers_end"
ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe $env{MODALIAS}"
SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="SD", RUN+="/sbin/modprobe tifm_sd"
SUBSYSTEM=="tifm", ENV{TIFM_CARD_TYPE}=="MS", RUN+="/sbin/modprobe tifm_ms"
SUBSYSTEM=="memstick", RUN+="/sbin/modprobe ms_block mspro_block"
SUBSYSTEM=="i2o", RUN+="/sbin/modprobe i2o_block"
SUBSYSTEM=="module", KERNEL=="parport_pc", RUN+="/sbin/modprobe ppdev"
KERNEL=="mtd*ro", ENV{MTD_FTL}=="smartmedia", RUN+="/sbin/modprobe sm_ftl"
LABEL="drivers_end"

View File

@ -26,14 +26,9 @@ dist_udevrules_DATA += \
60-persistent-storage.rules
endif
if HAVE_MODULES
if HAVE_LIBKMOD
if HAVE_KMOD
dist_udevrules_DATA += \
80-drivers.rules
else
dist_udevrules_DATA += \
80-drivers-modprobe.rules
endif
endif
if ENABLE_KEYMAP

View File

@ -2,7 +2,6 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-DMODPROBE=\"$(MODPROBE)\" \
-DROOTPREFIX=\"$(rootprefix)\" \
-DUDEV_HWDB_DIR=\"$(udevhwdbdir)\" \
-DUDEV_HWDB_BIN=\"$(udevhwdbbin)\" \
@ -77,13 +76,13 @@ libudev_core_la_SOURCES += \
udev-builtin-blkid.c
endif
if HAVE_MODULES
if HAVE_KMOD
libudev_core_la_SOURCES += \
udev-builtin-kmod.c
if HAVE_LIBKMOD
libudev_core_la_CFLAGS += $(KMOD_CFLAGS)
libudev_core_la_LIBADD += $(KMOD_LIBS)
endif
libudev_core_la_CFLAGS += \
$(KMOD_CFLAGS)
libudev_core_la_LIBADD += \
$(KMOD_LIBS)
endif
#

View File

@ -27,20 +27,16 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#ifdef HAVE_LIBKMOD
#include <libkmod.h>
#endif
#include "udev.h"
static struct kmod_ctx *ctx = NULL;
static int load_module(struct udev *udev, const char *alias) {
int err;
#ifdef HAVE_LIBKMOD
struct kmod_list *list = NULL;
struct kmod_list *l;
int err;
err = kmod_module_new_from_lookup(ctx, alias, &list);
if (err < 0)
@ -64,24 +60,6 @@ static int load_module(struct udev *udev, const char *alias) {
}
kmod_module_unref_list(list);
#else
/*
These 3 temporaries are needed because argv (below) is a const pointer, not pointer to const
*/
char *tmp_alias = strdup(alias);
char *tmp_modprobe = strdup(MODPROBE);
char *tmp_bq = strdup("-bq");
char *const argv[] = { tmp_modprobe, tmp_bq, tmp_alias, 0 };
err = execute_command(MODPROBE, argv);
free(tmp_alias);
free(tmp_modprobe);
free(tmp_bq);
#endif
/* both 'kmod_module_new_from_lookup' and 'execute_command' return <0 on error
so it is ok to assign both to 'err' */
return err;
}
@ -93,10 +71,8 @@ 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 || !streq(argv[1], "load")) {
log_error("expect: %s load <module>", argv[0]);
@ -113,7 +89,6 @@ 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;
@ -124,19 +99,15 @@ static int builtin_kmod_init(struct udev *udev) {
log_debug("Load module index");
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");
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) {
log_debug("Validate module index");
@ -144,16 +115,13 @@ 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,
};

View File

@ -39,7 +39,7 @@ static const struct udev_builtin *builtins[] = {
#ifdef ENABLE_KEYMAP
[UDEV_BUILTIN_KEYBOARD] = &udev_builtin_keyboard,
#endif
#ifdef HAVE_MODULES
#ifdef HAVE_KMOD
[UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
#endif
[UDEV_BUILTIN_NET_ID] = &udev_builtin_net_id,

View File

@ -154,7 +154,7 @@ enum udev_builtin_cmd {
#ifdef ENABLE_KEYMAP
UDEV_BUILTIN_KEYBOARD,
#endif
#ifdef HAVE_MODULES
#ifdef HAVE_KMOD
UDEV_BUILTIN_KMOD,
#endif
UDEV_BUILTIN_NET_ID,
@ -180,7 +180,7 @@ extern const struct udev_builtin udev_builtin_input_id;
#ifdef ENABLE_KEYMAP
extern const struct udev_builtin udev_builtin_keyboard;
#endif
#ifdef HAVE_MODULES
#ifdef HAVE_KMOD
extern const struct udev_builtin udev_builtin_kmod;
#endif
extern const struct udev_builtin udev_builtin_net_id;

View File

@ -53,8 +53,9 @@ test_device_nodes_LDADD = \
$(top_builddir)/src/shared/libudev_shared.la \
$(top_builddir)/src/libudev/libudev-private.la
if HAVE_LIBKMOD
test_udev_LDADD += $(KMOD_LIBS)
if HAVE_KMOD
test_udev_LDADD += \
$(KMOD_LIBS)
endif
test_udev_CPPFLAGS = \