summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2012-11-02 17:26:11 +0100
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2012-11-23 13:45:10 +0100
commitb49360d9485fc5d003e167f18333ac2e59b8573b (patch)
tree7081df110fd468a88e9785b6c4d6555c03162691 /src/config.c
parent3bf7e9f76f73eb4d98d6c991a6a6da66c1311ad0 (diff)
downloadconnman-b49360d9485fc5d003e167f18333ac2e59b8573b.tar.gz
connman-b49360d9485fc5d003e167f18333ac2e59b8573b.tar.bz2
connman-b49360d9485fc5d003e167f18333ac2e59b8573b.zip
config: Factor out config inotify handler
The inotify code can be reused. So before we introduce a new generic inotify API, let's factor out in order to simplify the review process.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/src/config.c b/src/config.c
index 46869144..16fed8da 100644
--- a/src/config.c
+++ b/src/config.c
@@ -562,6 +562,57 @@ static int read_configs(void)
return 0;
}
+static void config_notify_handler(struct inotify_event *event,
+ const char *ident)
+{
+ char *ext;
+
+ if (ident == NULL)
+ return;
+
+ if (g_str_has_suffix(ident, ".config") == FALSE)
+ return;
+
+ ext = g_strrstr(ident, ".config");
+ if (ext == NULL)
+ return;
+
+ *ext = '\0';
+
+ if (validate_ident(ident) == FALSE) {
+ connman_error("Invalid config ident %s", ident);
+ return;
+ }
+
+ if (event->mask & IN_CREATE)
+ create_config(ident);
+
+ if (event->mask & IN_MODIFY) {
+ struct connman_config *config;
+
+ config = g_hash_table_lookup(config_table, ident);
+ if (config != NULL) {
+ int ret;
+
+ g_hash_table_remove_all(config->service_table);
+ load_config(config);
+ 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);
+ }
+ }
+ }
+
+ if (event->mask & IN_DELETE)
+ g_hash_table_remove(config_table, ident);
+}
+
static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
gpointer user_data)
{
@@ -593,7 +644,6 @@ static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
while (bytes_read > 0) {
struct inotify_event *event;
- gchar *ext;
gchar *ident;
gsize len;
@@ -612,50 +662,7 @@ static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
next_event += len;
bytes_read -= len;
- if (ident == NULL)
- continue;
-
- if (g_str_has_suffix(ident, ".config") == FALSE)
- continue;
-
- ext = g_strrstr(ident, ".config");
- if (ext == NULL)
- continue;
-
- *ext = '\0';
-
- if (validate_ident(ident) == FALSE) {
- connman_error("Invalid config ident %s", ident);
- continue;
- }
-
- if (event->mask & IN_CREATE)
- create_config(ident);
-
- if (event->mask & IN_MODIFY) {
- struct connman_config *config;
-
- config = g_hash_table_lookup(config_table, ident);
- if (config != NULL) {
- int ret;
-
- g_hash_table_remove_all(config->service_table);
- load_config(config);
- 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);
- }
- }
- }
-
- if (event->mask & IN_DELETE)
- g_hash_table_remove(config_table, ident);
+ config_notify_handler(event, ident);
}
return TRUE;