From: Daniel Wagner <daniel.wag...@bmw-carit.de>

When we open the policy file and try to parse we might run
into an error. Instead of freeing the policy we just need
to reset it to the defaults and then try to apply the new settings.
We should reallyt not unref the policy on the error case because
the policy lifetime is attached to the lifetime of the file not
on the result of the parsing.
---
 plugins/session_policy_local.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/plugins/session_policy_local.c b/plugins/session_policy_local.c
index 5a8f6b8..aa734a1 100644
--- a/plugins/session_policy_local.c
+++ b/plugins/session_policy_local.c
@@ -294,6 +294,8 @@ static int load_policy(struct policy_data *policy)
        char *str, **tokens;
        int i, err = 0;
 
+       connman_session_set_default_config(config);
+
        pathname = g_strdup_printf("%s/%s", POLICYDIR, policy->ident);
        if(pathname == NULL)
                return -ENOMEM;
@@ -318,8 +320,6 @@ static int load_policy(struct policy_data *policy)
        if (str != NULL) {
                config->roaming_policy = 
connman_session_parse_roaming_policy(str);
                g_free(str);
-       } else {
-               config->roaming_policy = CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
        }
 
        str = g_key_file_get_string(keyfile, "Default", "ConnectionType",
@@ -327,20 +327,18 @@ static int load_policy(struct policy_data *policy)
        if (str != NULL) {
                config->type = connman_session_parse_connection_type(str);
                g_free(str);
-       } else {
-               config->type = CONNMAN_SESSION_TYPE_ANY;
        }
 
        config->ecall = g_key_file_get_boolean(keyfile, "Default",
                                                "EmergencyCall", NULL);
 
-       g_slist_free(config->allowed_bearers);
-       config->allowed_bearers = NULL;
-
        str = g_key_file_get_string(keyfile, "Default", "AllowedBearers",
                                NULL);
 
        if (str != NULL) {
+               g_slist_free(config->allowed_bearers);
+               config->allowed_bearers = NULL;
+
                tokens = g_strsplit(str, " ", 0);
 
                for (i = 0; tokens[i] != NULL; i++) {
@@ -352,11 +350,6 @@ static int load_policy(struct policy_data *policy)
 
                g_free(str);
                g_strfreev(tokens);
-       } else {
-               config->allowed_bearers = g_slist_append(NULL,
-                               GINT_TO_POINTER(CONNMAN_SERVICE_TYPE_UNKNOWN));
-               if (config->allowed_bearers == NULL)
-                       err = -ENOMEM;
        }
 
        g_key_file_free(keyfile);
@@ -397,6 +390,7 @@ static void notify_handler(struct inotify_event *event,
                                         const char *ident)
 {
        struct policy_data *policy;
+       int err;
 
        if (ident == NULL)
                return;
@@ -418,8 +412,10 @@ static void notify_handler(struct inotify_event *event,
        if (event->mask & IN_MODIFY) {
                connman_info("Policy modifed for '%s'", ident);
 
-               if (load_policy(policy) < 0) {
-                       remove_policy(policy);
+               err = load_policy(policy);
+               if (err < 0) {
+                       connman_warn("Loading policy file '%s' failed with %s",
+                                       ident, strerror(-err));
                        return;
                }
        }
-- 
1.8.2.rc3.16.gce432ca

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to