From: Daniel Wagner Date: Fri, 2 Nov 2012 16:26:11 +0000 (+0100) Subject: config: Factor out config inotify handler X-Git-Tag: 1.10~138 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b49360d9485fc5d003e167f18333ac2e59b8573b;p=platform%2Fupstream%2Fconnman.git 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. --- diff --git a/src/config.c b/src/config.c index 4686914..16fed8d 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;