Commit 6079aaa8 authored by phdeswer's avatar phdeswer

Pre-eliminary (lib)kmod support

Signed-off-by: phdeswer's avatarPhilippe De Swert <philippedeswert@gmail.com>
parent 86af2b63
......@@ -119,6 +119,7 @@ PKG_CHECK_MODULES([USB_MODED], [
dbus-glib-1 >= 0.78
gobject-2.0 >= 2.16.6
gio-2.0
libkmod
])
AC_SUBST(USB_MODED_LIBS)
......
......@@ -27,6 +27,8 @@
#include <glib.h>
#include <libkmod.h>
#include "usb_moded.h"
#include "usb_moded-modules.h"
#include "usb_moded-log.h"
......@@ -39,6 +41,9 @@
#include "usb_moded-modes.h"
#endif
/* kmod context - initialized at start in usb_moded_init */
struct kmod_ctx *ctx;
/** load module
*
* @param module Name of the module to load
......@@ -47,8 +52,9 @@
*/
int usb_moded_load_module(const char *module)
{
gchar *command;
int ret = 0;
#ifdef NO_KMOD
gchar *command;
command = g_strconcat("modprobe ", module, NULL);
ret = system(command);
......@@ -63,6 +69,30 @@ int usb_moded_load_module(const char *module)
ret = system(command);
}
g_free(command);
#else
const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
struct kmod_module *mod;
const char *charging_args = NULL;
ret = kmod_module_new_from_name(ctx, module, &mod);
if(!strcmp(module, MODULE_MASS_STORAGE) && (ret != 0))
{
ret = kmod_module_new_from_name(ctx, MODULE_FILE_STORAGE, &mod);
}
if(!strcmp(module, MODULE_CHARGING) && (ret != 0))
{
/* split the string in module name and arguments, if it still fails do the same
for MODULE_CHARGE_FALLBACK */
}
if(!charging_args)
ret = kmod_module_probe_insert_module(mod, probe_flags, NULL, NULL, NULL, NULL);
else
ret = kmod_module_probe_insert_module(mod, probe_flags, charging_args, NULL, NULL, NULL);
kmod_module_unref(mod);
#endif /* NO_KMOD */
if( ret == 0)
log_info("Module %s loaded successfully\n", module);
return(ret);
......@@ -76,12 +106,22 @@ int usb_moded_load_module(const char *module)
*/
int usb_moded_unload_module(const char *module)
{
gchar *command;
int ret = 0;
#ifdef NO_KMOD
gchar *command;
command = g_strconcat("rmmod ", module, NULL);
ret = system(command);
g_free(command);
#else
struct kmod_module *mod;
kmod_module_new_from_name(ctx, module, &mod);
ret = kmod_module_remove_module(mod, KMOD_REMOVE_NOWAIT);
kmod_module_unref(mod);
#endif /* NO_KMOD */
return(ret);
}
......
......@@ -29,6 +29,8 @@
#include <string.h>
#endif
#include <libkmod.h>
#include "usb_moded.h"
#include "usb_moded-modes.h"
#include "usb_moded-dbus.h"
......@@ -52,7 +54,7 @@ extern const char *log_name;
extern int log_level;
extern int log_type;
extern gboolean rescue_mode;
gboolean rescue_mode;
gboolean runlevel_ignore = FALSE;
gboolean hw_fallback = FALSE;
......@@ -413,6 +415,7 @@ static void usb_moded_init(void)
char readbuf[MAX_READ_BUF];
FILE *proc_fd;
#endif /* NOKIA_NSU */
extern struct kmod_ctx *ctx;
current_mode.connected = FALSE;
current_mode.mounted = FALSE;
......@@ -443,6 +446,11 @@ static void usb_moded_init(void)
if(check_trigger())
trigger_init();
#endif /* UDEV */
/* kmod init */
ctx = kmod_new(NULL, NULL);
kmod_load_resources(ctx);
/* TODO: add more start-up clean-up and init here if needed */
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment