technology: return already enabled when tethering is enabled
[framework/connectivity/connman.git] / src / config.c
index aba06c4..5363dc3 100644 (file)
@@ -68,6 +68,7 @@ static int inotify_wd = -1;
 
 static GIOChannel *inotify_channel = NULL;
 static uint inotify_watch = 0;
+static connman_bool_t cleanup = FALSE;
 
 #define INTERNAL_CONFIG_PREFIX           "__internal"
 
@@ -133,6 +134,9 @@ static void unregister_service(gpointer data)
        char *service_id;
        GSList *list;
 
+       if (cleanup == TRUE)
+               goto free_only;
+
        connman_info("Removing service configuration %s",
                                                config_service->ident);
 
@@ -154,6 +158,7 @@ static void unregister_service(gpointer data)
                                                                service_id);
        }
 
+free_only:
        g_free(config_service->ident);
        g_free(config_service->type);
        g_free(config_service->name);
@@ -624,9 +629,20 @@ static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
 
                        config = g_hash_table_lookup(config_table, ident);
                        if (config != NULL) {
+                               int ret;
+
                                g_hash_table_remove_all(config->service_table);
                                load_config(config);
-                               __connman_service_provision_changed(ident);
+                               ret = __connman_service_provision_changed(ident);
+                               if (ret > 0) {
+                                       /*
+                                        * Re-scan the config file for any
+                                        * changes
+                                        */
+                                       g_hash_table_remove_all(config->service_table);
+                                       load_config(config);
+                                       __connman_service_provision_changed(ident);
+                               }
                        }
                }
 
@@ -712,10 +728,14 @@ void __connman_config_cleanup(void)
 {
        DBG("");
 
+       cleanup = TRUE;
+
        remove_watch();
 
        g_hash_table_destroy(config_table);
        config_table = NULL;
+
+       cleanup = FALSE;
 }
 
 static char *config_pem_fsid(const char *pem_file)
@@ -828,6 +848,10 @@ static void provision_service(gpointer key, gpointer value, gpointer user_data)
 
        if (config->passphrase != NULL)
                __connman_service_set_string(service, "Passphrase", config->passphrase);
+
+       __connman_service_mark_dirty();
+
+       __connman_service_save(service);
 }
 
 int __connman_config_provision_service(struct connman_service *service)
@@ -856,10 +880,11 @@ int __connman_config_provision_service(struct connman_service *service)
 }
 
 int __connman_config_provision_service_ident(struct connman_service *service,
-                                                       const char *ident)
+                       const char *ident, const char *file, const char *entry)
 {
        enum connman_service_type type;
        struct connman_config *config;
+       int ret = 0;
 
        DBG("service %p", service);
 
@@ -869,9 +894,47 @@ int __connman_config_provision_service_ident(struct connman_service *service,
                return -ENOSYS;
 
        config = g_hash_table_lookup(config_table, ident);
-       if(config != NULL)
+       if(config != NULL) {
+               GHashTableIter iter;
+               gpointer value, key;
+               gboolean found = FALSE;
+
+               g_hash_table_iter_init(&iter, config->service_table);
+
+               /*
+                * Check if we need to remove individual service if it
+                * is missing from config file.
+                */
+               if (file != NULL && entry != NULL) {
+                       while (g_hash_table_iter_next(&iter, &key,
+                                                       &value) == TRUE) {
+                               struct connman_config_service *config = value;
+
+                               if (g_strcmp0(config->config_ident,
+                                                               file) == 0 &&
+                                               g_strcmp0(config->config_entry,
+                                                               entry) == 0) {
+                                       found = TRUE;
+                                       break;
+                               }
+                       }
+
+                       DBG("found %d ident %s file %s entry %s", found, ident,
+                                                               file, entry);
+
+                       if (found == FALSE) {
+                               /*
+                                * The entry+8 will skip "service_" prefix
+                                */
+                               g_hash_table_remove(config->service_table,
+                                               entry + 8);
+                               ret = 1;
+                       }
+               }
+
                g_hash_table_foreach(config->service_table,
                                                provision_service, service);
+       }
 
-       return 0;
+       return ret;
 }