Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pre-eliminary (lib)kmod support
Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
  • Loading branch information
philippedeswert committed Nov 13, 2012
1 parent 86af2b6 commit 6079aaa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -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)
Expand Down
44 changes: 42 additions & 2 deletions src/usb_moded-modules.c
Expand Up @@ -27,6 +27,8 @@

#include <glib.h>

#include <libkmod.h>

#include "usb_moded.h"
#include "usb_moded-modules.h"
#include "usb_moded-log.h"
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/usb_moded.c
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
}

Expand Down

0 comments on commit 6079aaa

Please sign in to comment.