From: Daniel Wagner <[email protected]>

Monitor changes on the config files. Either create, modify or destroy
them according the events we get from the inotify interface.
---
 plugins/session_policy_ivi.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index e5ead6a..7632acb 100644
--- a/plugins/session_policy_ivi.c
+++ b/plugins/session_policy_ivi.c
@@ -25,6 +25,7 @@
 
 #include <errno.h>
 #include <string.h>
+#include <sys/inotify.h>
 
 #include <glib.h>
 
@@ -36,6 +37,7 @@
 #include <connman/log.h>
 #include <connman/session.h>
 #include <connman/dbus.h>
+#include <connman/inotify.h>
 
 #define POLICYDIR STORAGEDIR "/session_policy_ivi"
 
@@ -234,6 +236,41 @@ static struct policy_data *create_policy(const char *ident)
        return policy;
 }
 
+static void notify_handler(struct inotify_event *event,
+                                        const char *ident)
+{
+       struct policy_data *policy;
+
+       if (ident == NULL)
+               return;
+
+       if (event->mask & IN_CREATE) {
+               connman_info("Policy added for '%s'", ident);
+               create_policy(ident);
+       }
+
+       if (event->mask & IN_MODIFY) {
+               connman_info("Policy modifed for '%s'", ident);
+               policy = g_hash_table_lookup(ident_hash, ident);
+               if (policy != NULL) {
+                       load_policy(policy);
+
+                       connman_session_config_update(policy->session);
+               }
+       }
+
+       if (event->mask & IN_DELETE) {
+               connman_info("Policy deleted for '%s'", ident);
+               policy = g_hash_table_lookup(ident_hash, ident);
+
+               g_hash_table_remove(ident_hash, ident);
+               policy->ident = NULL;
+
+               if (policy->session == NULL)
+                       cleanup_policy(policy);
+       }
+}
+
 static int read_policies(void)
 {
        GDir *dir;
@@ -262,6 +299,10 @@ static int session_policy_ivi_init(void)
 {
        int err;
 
+       err = connman_inotify_register(POLICYDIR, notify_handler);
+       if (err < 0)
+               return err;
+
        connection = connman_dbus_get_connection();
        if (connection == NULL)
                return -EIO;
@@ -299,6 +340,8 @@ err:
 
        dbus_connection_unref(connection);
 
+       connman_inotify_unregister(POLICYDIR, notify_handler);
+
        return err;
 }
 
@@ -321,6 +364,8 @@ static void session_policy_ivi_exit(void)
        connman_session_policy_unregister(&session_policy_ivi);
 
        dbus_connection_unref(connection);
+
+       connman_inotify_unregister(POLICYDIR, notify_handler);
 }
 
 CONNMAN_PLUGIN_DEFINE(session_policy_ivi,
-- 
1.8.0.rc0

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to