Skip to content

Commit

Permalink
config: * Save udev path (if it exists) to keep working over upgrades…
Browse files Browse the repository at this point in the history
… (when no other config supplies the udev info)

        * Make it possible to set any basic configuration setting through a generic function

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed May 24, 2013
1 parent 64dd2dd commit d96e378
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/usb_moded-config.c
Expand Up @@ -287,7 +287,7 @@ const char * get_mode_setting(void)
return(get_conf_string(MODE_SETTING_ENTRY, MODE_SETTING_KEY));
}

int set_mode_setting(const char *mode)
int set_config_setting(const char *entry, const char *key, const char *value)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
Expand All @@ -302,7 +302,7 @@ int set_mode_setting(const char *mode)
create_conf_file();
}

g_key_file_set_string(settingsfile, MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode);
g_key_file_set_string(settingsfile, entry, key, value);
keyfile = g_key_file_to_data (settingsfile, NULL, NULL);
/* free the settingsfile before writing things out to be sure
the contents will be correctly written to file afterwards.
Expand All @@ -314,6 +314,11 @@ int set_mode_setting(const char *mode)
return(!ret);
}

int set_mode_setting(const char *mode)
{
return (set_config_setting(MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode));
}

int set_network_setting(const char *config, const char *setting)
{
GKeyFile *settingsfile;
Expand Down Expand Up @@ -359,6 +364,9 @@ int conf_file_merge(void)
GString *keyfile_string = NULL;
GKeyFile *settingsfile;
int ret = 0, test = 0;
#ifdef UDEV
const gchar *udev = 0;
#endif /* UDEV */

confdir = g_dir_open(CONFIG_FILE_DIR, 0, NULL);
if(!confdir)
Expand Down Expand Up @@ -395,6 +403,10 @@ int conf_file_merge(void)
{
/* store mode info to add it later as we want to keep it */
mode = get_mode_setting();
#ifdef UDEV
/* store udev path (especially important for the upgrade path */
udev = find_udev_path();
#endif /* UDEV */
break;
}
/* load contents of file, if it fails skip to next one */
Expand Down Expand Up @@ -423,11 +435,22 @@ int conf_file_merge(void)
{
set_mode_setting(mode);
}
#ifdef UDEV
if(udev)
{
set_settings_option(UDEV_PATH_ENTRY, UDEV_PATH_KEY, udev);
}
#endif /* UDEV */
}
else
ret = 1;
if(mode)
free((void *)mode);
#ifdef UDEV
if(udev)
free((void *)udev);
#endif /* UDEV */

g_dir_close(confdir);
return(ret);
}
4 changes: 2 additions & 2 deletions src/usb_moded-config.h
Expand Up @@ -20,7 +20,7 @@
*/


#define CONFIG_FILE_DIR "/etc/usb-moded"
#define CONFIG_FILE_DIR "/tmp/etc/usb-moded"
#define FS_MOUNT_CONFIG_FILE CONFIG_FILE_DIR"/usb-moded.ini"

#define MODE_SETTING_ENTRY "usbmode"
Expand Down Expand Up @@ -76,7 +76,7 @@ const char * get_trigger_value(void);
const char * get_network_ip(void);
const char * get_network_interface(void);
const char * get_network_gateway(void);

const char * get_soft_connect_path(void);

int conf_file_merge(void);
int set_config_setting(const char *entry, const char *key, const char *value);

0 comments on commit d96e378

Please sign in to comment.