summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2011-04-11 11:07:37 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2011-04-11 12:02:45 +0200
commitc195cbf793846ef4b909cfbddfdae1f0b89f664f (patch)
tree7c7bc1aa65e0d40c664f69412ac1499c5904f6f0 /src/config.c
parent35a50240fe9e681d06421cb4d0920a1ffe049085 (diff)
downloadconnman-c195cbf793846ef4b909cfbddfdae1f0b89f664f.tar.gz
connman-c195cbf793846ef4b909cfbddfdae1f0b89f664f.tar.bz2
connman-c195cbf793846ef4b909cfbddfdae1f0b89f664f.zip
config: Save D-Bus provisioned files
They will not be able to overwrite protected configs though.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c67
1 files changed, 60 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c
index 932a1085..974643f6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -67,6 +67,7 @@ static GIOChannel *inotify_channel = NULL;
static uint inotify_watch = 0;
#define NONFS_CONFIG_NAME "internal"
+#define INTERNAL_CONFIG_PREFIX "__internal"
/* Definition of possible strings in the .config files */
#define CONFIG_KEY_NAME "Name"
@@ -446,18 +447,70 @@ static struct connman_config *create_config(const char *ident)
return config;
}
-int __connman_config_load_service(GKeyFile *keyfile, const char *group)
+int __connman_config_load_service(GKeyFile *keyfile, const char *group,
+ connman_bool_t persistent)
{
- struct connman_config *config = g_hash_table_lookup(config_table,
- NONFS_CONFIG_NAME);
+ struct connman_config *config;
+ const char *service_name;
+ char *ident, *filename = NULL, *content = NULL;
+ gsize content_length;
+ int err;
+
+ service_name = group + strlen("service_");
+ ident = g_strdup_printf("%s_%s", INTERNAL_CONFIG_PREFIX, service_name);
+ if (ident == NULL)
+ return -ENOMEM;
+ DBG("ident %s", ident);
+
+ config = g_hash_table_lookup(config_table, ident);
if (config == NULL) {
- config = create_config(NONFS_CONFIG_NAME);
- if (config == NULL)
- return -ENOMEM;
+ config = create_config(ident);
+ if (config == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ config->protected = FALSE;
+ }
+
+ err = load_service(keyfile, group, config);
+ if (persistent == FALSE || err < 0)
+ goto out;
+
+ g_key_file_set_string(keyfile, "global", CONFIG_KEY_NAME,
+ service_name);
+ g_key_file_set_string(keyfile, "global", CONFIG_KEY_DESC,
+ "Internal Config File");
+
+ content = g_key_file_to_data(keyfile, &content_length, NULL);
+ if (content == NULL) {
+ err = -EIO;
+ goto out;
+ }
+
+ filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
+ if (filename == NULL) {
+ err = -ENOMEM;
+ goto out;
}
- return load_service(keyfile, group, config);
+ DBG("Saving %d bytes to %s", content_length, filename);
+
+ if (g_file_set_contents(filename, content,
+ content_length, NULL) == FALSE) {
+ err = -EIO;
+ goto out;
+ }
+
+ return 0;
+
+out:
+ g_free(ident);
+ g_free(content);
+ g_free(filename);
+
+ return err;
}
static int read_configs(void)