Inotify will send modify event after create event when user has
copied the config file into config directory. Because of this
it is useless to act on create event. As a bonus we avoid
create/modify/create loop that was earlier done in the modify event
handling code.
}
if (event->mask & IN_CREATE)
}
if (event->mask & IN_CREATE)
+ return;
+
+ if (event->mask & IN_DELETE) {
+ g_hash_table_remove(config_table, ident);
+ return;
+ }
if (event->mask & IN_MODIFY) {
struct vpn_config *config;
if (event->mask & IN_MODIFY) {
struct vpn_config *config;
+ char *path = get_dir();
config = g_hash_table_lookup(config_table, ident);
if (config != NULL) {
config = g_hash_table_lookup(config_table, ident);
if (config != NULL) {
- char *path = get_dir();
-
g_hash_table_remove_all(config->provider_table);
load_config(config, path, REMOVE);
/* Re-scan the config file for any changes */
g_hash_table_remove_all(config->provider_table);
load_config(config, path, ADD);
g_hash_table_remove_all(config->provider_table);
load_config(config, path, REMOVE);
/* Re-scan the config file for any changes */
g_hash_table_remove_all(config->provider_table);
load_config(config, path, ADD);
+ } else {
+ /*
+ * Inotify will send create event followed by modify
+ * event for any config file that is copied to
+ * monitored directory. So in practice we should just
+ * ignore the create event and trust only the modify
+ * one in order to avoid create/remove/create loop
+ */
+ config = create_config(ident);
+ if (config != NULL)
+ load_config(config, path, ADD);
- if (event->mask & IN_DELETE)
- g_hash_table_remove(config_table, ident);
}
int __vpn_config_init(void)
}
int __vpn_config_init(void)