Commit 1bf3220b authored by Philippe De Swert's avatar Philippe De Swert

Primer for config file merging

Signed-off-by: default avatarPhilippe De Swert <>
parent df6665e3
......@@ -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}
Debug enabled: ${debug}
......@@ -286,3 +286,56 @@ int set_network_setting(const char *config, const char *setting)
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);
log_debug("No configuration. Creating defaults.\n");
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;
/* 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);
keyfile_string = g_strconcat(keyfile_string, g_key_file_to_data(settingsfile, NULL, NULL), NULL);
/* 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);
......@@ -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);
......@@ -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)
current_mode.module = strdup(module);
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