From: Daniel Wagner <[email protected]>
---
plugins/session_policy_ivi.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index 5e6b04b..9d3f457 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>
@@ -35,6 +36,7 @@
#include <connman/log.h>
#include <connman/session.h>
#include <connman/dbus.h>
+#include <connman/storage.h>
static DBusConnection *connection;
@@ -228,6 +230,52 @@ static connman_bool_t validate_ident(const char *ident)
return TRUE;
}
+static void notify_handler(struct inotify_event *event,
+ const char *ident)
+{
+ struct policy_data *policy;
+ char *ext;
+
+ if (ident == NULL)
+ return;
+
+ if (g_str_has_suffix(ident, ".policy") == FALSE)
+ return;
+
+ ext = g_strrstr(ident, ".policy");
+ if (ext == NULL)
+ return;
+
+ *ext = '\0';
+
+ if (validate_ident(ident) == FALSE) {
+ connman_error("Invalid policy ident %s", ident);
+ return;
+ }
+
+ if (event->mask & IN_CREATE)
+ create_policy(ident);
+
+ if (event->mask & IN_MODIFY) {
+ 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) {
+ 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;
@@ -277,6 +325,8 @@ static int session_policy_ivi_init(void)
{
int err;
+ connman_storage_notify_register(notify_handler);
+
connection = connman_dbus_get_connection();
if (connection == NULL)
return -EIO;
@@ -314,6 +364,8 @@ err:
dbus_connection_unref(connection);
+ connman_storage_notify_unregister(notify_handler);
+
return err;
}
@@ -336,6 +388,8 @@ static void session_policy_ivi_exit(void)
connman_session_policy_unregister(&session_policy_ivi);
dbus_connection_unref(connection);
+
+ connman_storage_notify_unregister(notify_handler);
}
CONNMAN_PLUGIN_DEFINE(session_policy_ivi,
--
1.7.12.1.382.gb0576a6
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman