From a3074ee91160993f69bb83fd16b2cede46030405 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Dec 2017 12:09:41 +0100 Subject: [PATCH] ifcfg-rh: add and use nm_inotify_helper_clear_watch() helper --- .../plugins/ifcfg-rh/nm-inotify-helper.h | 13 +++++++++++ .../ifcfg-rh/nms-ifcfg-rh-connection.c | 22 ++++--------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.h b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.h index 2715f3eec5..b887ae378a 100644 --- a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.h +++ b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.h @@ -43,4 +43,17 @@ int nm_inotify_helper_add_watch (NMInotifyHelper *helper, const char *path); void nm_inotify_helper_remove_watch (NMInotifyHelper *helper, int wd); +static inline gboolean +nm_inotify_helper_clear_watch (NMInotifyHelper *helper, int *wd) +{ + int x; + + if (wd && ((x = *wd) >= 0)) { + *wd = -1; + nm_inotify_helper_remove_watch (helper, x); + return TRUE; + } + return FALSE; +} + #endif /* __NM_INOTIFY_HELPER_H__ */ diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index c8712f1833..5d3428d6bf 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -220,28 +220,14 @@ path_watch_stop (NMIfcfgConnection *self) nm_clear_g_signal_handler (priv->inotify_helper, &priv->ih_event_id); - if (priv->file_wd >= 0) { - nm_inotify_helper_remove_watch (priv->inotify_helper, priv->file_wd); - priv->file_wd = -1; - } + nm_inotify_helper_clear_watch (priv->inotify_helper, &priv->file_wd); + nm_inotify_helper_clear_watch (priv->inotify_helper, &priv->keyfile_wd); + nm_inotify_helper_clear_watch (priv->inotify_helper, &priv->routefile_wd); + nm_inotify_helper_clear_watch (priv->inotify_helper, &priv->route6file_wd); nm_clear_g_free (&priv->keyfile); - if (priv->keyfile_wd >= 0) { - nm_inotify_helper_remove_watch (priv->inotify_helper, priv->keyfile_wd); - priv->keyfile_wd = -1; - } - nm_clear_g_free (&priv->routefile); - if (priv->routefile_wd >= 0) { - nm_inotify_helper_remove_watch (priv->inotify_helper, priv->routefile_wd); - priv->routefile_wd = -1; - } - nm_clear_g_free (&priv->route6file); - if (priv->route6file_wd >= 0) { - nm_inotify_helper_remove_watch (priv->inotify_helper, priv->route6file_wd); - priv->route6file_wd = -1; - } } static void