From 4a6994312993c47ef0773732237027940c786989 Mon Sep 17 00:00:00 2001 From: Philippe De Swert Date: Tue, 13 Nov 2012 21:06:11 +0200 Subject: [PATCH] Finalize kmod migration, prep new release Signed-off-by: Philippe De Swert --- configure.ac | 2 +- debian/changelog | 7 +++++++ src/usb_moded-modules.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a85dddf..1676ba5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([usb_moded], [0.53]) +AC_INIT([usb_moded], [0.54]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_CONFIG_HEADER([config.h]) diff --git a/debian/changelog b/debian/changelog index a992e91..0885507 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +usb-moded (0.54) unstable; urgency=low + + * Instead of spawning shells with system() use libkmod + * Make config file optional as defaults work for most + + -- Philippe De Swert Tue. 13 Nov 2012 18:56:23 +0300 + usb-moded (0.53) unstable; urgency=low * Un-nokia to make usb_moded more generic diff --git a/src/usb_moded-modules.c b/src/usb_moded-modules.c index 19af753..ed4262b 100644 --- a/src/usb_moded-modules.c +++ b/src/usb_moded-modules.c @@ -126,12 +126,31 @@ int usb_moded_unload_module(const char *module) return(ret); } +/** Check which state a module is in + * + * @return 1 if loaded, 0 when not loaded + */ +static int module_state_check(const char *module) +{ + int ret = 0; + struct kmod_module *mod; + + kmod_module_new_from_name(ctx, module, &mod); + ret = kmod_module_get_initstate(mod); + kmod_module_unref(mod); + if( ret == KMOD_MODULE_LIVE) + return(1); + else + return(0); +} + /** find which module is loaded * * @return The name of the loaded module, or NULL if no modules are loaded. */ const char * usb_moded_find_module(void) { +#ifdef NO_KMOD FILE *stream = 0; const char *result = 0; @@ -181,8 +200,26 @@ const char * usb_moded_find_module(void) } pclose(stream); } + +return result; +#endif /* NO_KMOD */ - return result; + if(module_state_check("g_nokia")) + return(MODULE_NETWORK); + else if(module_state_check("g_ether")) + return(MODULE_WINDOWS_NET); + else if(module_state_check("g_ncm")) + return("g_ncm"); + else if(module_state_check("g_ffs")) + return(MODULE_MTP); + else if(module_state_check("g_mass_storage")) + return(MODULE_MASS_STORAGE); + else if(module_state_check("g_file_storage")) + return(MODULE_FILE_STORAGE); + else if(module_state_check(get_usb_module())) + return(get_usb_module()); + /* no module loaded */ + return(0); } /** clean up for modules when usb gets disconnected