diff --git a/configure.ac b/configure.ac index 0efd829..5e1370c 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ test_gcc_flag() { # We use gnu99 instead of c99 because many have interpreted the standard # in a way that int64_t isn't defined on non-64 bit platforms. -CFLAGS="-std=gnu99 -Wall -W -Wextra -pedantic -pipe -Wformat -Wold-style-definition -Wdeclaration-after-statement -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wno-unused-parameter" +CFLAGS="-Os -std=gnu99 -Wall -W -Wextra -pedantic -pipe -Wformat -Wold-style-definition -Wdeclaration-after-statement -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wno-unused-parameter -finline-small-functions" AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug],[Enable debug @<:@default=false@:>@]), [case "${enableval}" in @@ -145,6 +145,7 @@ echo " Compiler: ${CC} CFLAGS: ${CFLAGS} + LDFLAGS: ${LDFLAGS} Debug enabled: ${debug} " diff --git a/src/usb_moded-config.c b/src/usb_moded-config.c index c1160e1..7fe3fa5 100644 --- a/src/usb_moded-config.c +++ b/src/usb_moded-config.c @@ -286,3 +286,56 @@ int set_network_setting(const char *config, const char *setting) #endif +int conf_file_merge(void) +{ + GDir *confdir; + struct stat fileinfo, dir; + const gchar *filename; + gchar *keyfile_string = NULL; + GKeyFile *settingsfile; + int ret = 0, test = 0; + + confdir = g_dir_open(CONFIG_FILE_DIR, 0, NULL); + if(!confdir) + { + log_debug("No configuration. Creating defaults.\n"); + create_conf_file(); + return (ret); + } + + if (stat(FS_MOUNT_CONFIG_FILE, &fileinfo) == -1) + { + /* conf file not created yet, merge all */ + goto merge; + } + + /* config file is created, so the dir must exists */ + stat(CONFIG_FILE_DIR, &dir); + + /* st_mtime is changed by file modifications, st_mtime of a directory is changed by the creation or deletion of files in that directory. + So if the st_mtime of the config file is equal to the directory time we can be sure the config is untouched and we do not need + to re-merge the config. + */ + if(fileinfo.st_mtime == dir.st_mtime) + return 0; + +merge: + /* check each ini file and get contents */ + while((filename = g_dir_read_name(confdir)) != NULL) + { + settingsfile = g_key_file_new(); + /* load contents of file, if it fails skip to next one */ + test = g_key_file_load_from_file(settingsfile, filename, G_KEY_FILE_NONE, NULL); + if(!test) + break; + keyfile_string = g_strconcat(keyfile_string, g_key_file_to_data(settingsfile, NULL, NULL), NULL); + g_key_file_free(settingsfile); + } + + /* write out merged config file */ + /* g_file_set_contents returns 1 on succes, this function returns 0 */ + ret = !g_file_set_contents(FS_MOUNT_CONFIG_FILE, keyfile_string, -1, NULL); + + g_dir_close(confdir); + return(ret); +} diff --git a/src/usb_moded-config.h b/src/usb_moded-config.h index 8086869..0cd46a9 100644 --- a/src/usb_moded-config.h +++ b/src/usb_moded-config.h @@ -78,3 +78,5 @@ const char * get_network_interface(void); const char * get_network_gateway(void); const char * get_soft_connect_path(void); + +int conf_file_merge(void); diff --git a/src/usb_moded.c b/src/usb_moded.c index 9cc91bd..5dfaf24 100644 --- a/src/usb_moded.c +++ b/src/usb_moded.c @@ -416,7 +416,7 @@ inline const char * get_usb_mode(void) * @param module The module name for the requested mode * */ -inline void set_usb_module(const char *module) +void set_usb_module(const char *module) { free(current_mode.module); current_mode.module = strdup(module);