From 70afa9214bc983f004e5cb6bf46519d6884bc8db Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 12 Feb 2008 20:25:12 +0000 Subject: [PATCH] 2008-02-12 Dan Williams * system-settings/plugins/ifcfg-fedora/plugin.c - (watch_path): handle IN_DELETE_SELF too - (handle_connection_changed): notify when removing a connection - (stuff_changed): don't warn on unknown inotify watches; handle the case of a file moving out of the profile directory git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3312 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 8 +++ system-settings/plugins/ifcfg-fedora/plugin.c | 54 ++++++++++++++++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2127bcb3bc..f2597468ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-02-12 Dan Williams + + * system-settings/plugins/ifcfg-fedora/plugin.c + - (watch_path): handle IN_DELETE_SELF too + - (handle_connection_changed): notify when removing a connection + - (stuff_changed): don't warn on unknown inotify watches; handle the + case of a file moving out of the profile directory + 2008-02-12 Dan Williams * system-settings/plugins/ifcfg-fedora/parser.c diff --git a/system-settings/plugins/ifcfg-fedora/plugin.c b/system-settings/plugins/ifcfg-fedora/plugin.c index f23f8c7efc..dc38fa908d 100644 --- a/system-settings/plugins/ifcfg-fedora/plugin.c +++ b/system-settings/plugins/ifcfg-fedora/plugin.c @@ -123,7 +123,7 @@ watch_path (const char *path, const int inotify_fd, GHashTable *table) return; wd = inotify_add_watch (inotify_fd, path, - IN_CLOSE_WRITE | IN_CREATE | IN_DELETE | IN_MOVE | IN_MOVE_SELF); + IN_CLOSE_WRITE | IN_CREATE | IN_DELETE | IN_MOVE | IN_MOVE_SELF | IN_DELETE_SELF); if (wd == -1) { PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " inotify error watching '%s': errno %d", path, errno); @@ -439,6 +439,7 @@ handle_connection_changed (SCPluginIfcfg *plugin, if (!existing_cdata->ignored) g_signal_emit_by_name (plugin, "connection-removed", existing); g_object_unref (existing); + PLUGIN_PRINT (IFCFG_PLUGIN_NAME, " removed connection"); } } @@ -555,6 +556,29 @@ handle_profile_item_new (SCPluginIfcfg *plugin, const char *filename) g_free (path); } +typedef struct { + gboolean found; + const char *path; +} FindInfo; + +static void +find_path_helper (gpointer key, gpointer data, gpointer user_data) +{ + FindInfo *info = (FindInfo *) user_data; + + if (!info->found && !strcmp (data, info->path)) + info->found = TRUE; +} + +static gboolean +find_path (GHashTable *table, const char *path) +{ + FindInfo info = { FALSE, path }; + + g_hash_table_foreach (table, find_path_helper, &info); + return info.found; +} + static gboolean stuff_changed (GIOChannel *channel, GIOCondition cond, gpointer user_data) { @@ -577,10 +601,8 @@ stuff_changed (GIOChannel *channel, GIOCondition cond, gpointer user_data) NULL, NULL); } - if (!path && !strlen (filename)) { - PLUGIN_WARN (IFCFG_PLUGIN_NAME, "unhandled inotify event."); + if (!path && !strlen (filename)) continue; - } if (evt.wd == priv->profile_wd) { char *basename; @@ -604,18 +626,36 @@ stuff_changed (GIOChannel *channel, GIOCondition cond, gpointer user_data) } g_free (basename); } else { + char *fullpath; + gboolean path_found, delete = FALSE; + /* If the item was deleted, stop tracking its watch */ - if (evt.mask & (IN_DELETE | IN_DELETE_SELF)) { + if (evt.mask & (IN_DELETE | IN_DELETE_SELF)) + delete = TRUE; + + /* Track moves out of the profile directory */ + if ( (evt.mask & IN_MOVE_SELF) + && path + && strcmp (path, priv->profile) + && !strncmp (path, priv->profile, strlen (priv->profile)) + && !g_file_test (path, G_FILE_TEST_EXISTS)) + delete = TRUE; + + if (delete) { inotify_rm_watch (priv->ifd, evt.wd); g_hash_table_remove (priv->watch_table, GINT_TO_POINTER (evt.wd)); } - if (strlen (filename) && !strcmp (path, priv->profile)) { + fullpath = g_strdup_printf ("%s%s", priv->profile, filename); + path_found = find_path (priv->watch_table, fullpath); + + if (strlen (filename) && !strcmp (path, priv->profile) && !path_found) { /* Some file appeared */ handle_profile_item_new (plugin, filename); } else { - handle_profile_item_changed (plugin, path); + handle_profile_item_changed (plugin, path_found ? fullpath : path); } + g_free (fullpath); } }