ifcfg-rh: fix path_watch_stop() not to create inotify-helper

Commonly, we don't monitor files and hence don't need the inotify-helper
instance. We already access and construct the instance lazy, by
accessing the singleton getter only when needed.

However, path_watch_stop() would always access the singleton, hence
always create such an instance. In most cases there is nothing to clean,
and no such instance shall be created.

(cherry picked from commit 31f2a46639)
This commit is contained in:
Thomas Haller 2017-12-01 11:53:07 +01:00
parent 2bff4dd1a6
commit e5f41b763a

View file

@ -96,14 +96,6 @@ G_DEFINE_TYPE (NMIfcfgConnection, nm_ifcfg_connection, NM_TYPE_SETTINGS_CONNECTI
/*****************************************************************************/
static NMInotifyHelper *
_get_inotify_helper (NMIfcfgConnectionPrivate *priv)
{
if (!priv->inotify_helper)
priv->inotify_helper = g_object_ref (nm_inotify_helper_get ());
return priv->inotify_helper;
}
static gboolean
devtimeout_ready (gpointer user_data)
{
@ -225,35 +217,29 @@ static void
path_watch_stop (NMIfcfgConnection *self)
{
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
NMInotifyHelper *ih;
ih = _get_inotify_helper (priv);
nm_clear_g_signal_handler (ih, &priv->ih_event_id);
nm_clear_g_signal_handler (priv->inotify_helper, &priv->ih_event_id);
if (priv->file_wd >= 0) {
nm_inotify_helper_remove_watch (ih, priv->file_wd);
nm_inotify_helper_remove_watch (priv->inotify_helper, priv->file_wd);
priv->file_wd = -1;
}
g_free (priv->keyfile);
priv->keyfile = NULL;
nm_clear_g_free (&priv->keyfile);
if (priv->keyfile_wd >= 0) {
nm_inotify_helper_remove_watch (ih, priv->keyfile_wd);
nm_inotify_helper_remove_watch (priv->inotify_helper, priv->keyfile_wd);
priv->keyfile_wd = -1;
}
g_free (priv->routefile);
priv->routefile = NULL;
nm_clear_g_free (&priv->routefile);
if (priv->routefile_wd >= 0) {
nm_inotify_helper_remove_watch (ih, priv->routefile_wd);
nm_inotify_helper_remove_watch (priv->inotify_helper, priv->routefile_wd);
priv->routefile_wd = -1;
}
g_free (priv->route6file);
priv->route6file = NULL;
nm_clear_g_free (&priv->route6file);
if (priv->route6file_wd >= 0) {
nm_inotify_helper_remove_watch (ih, priv->route6file_wd);
nm_inotify_helper_remove_watch (priv->inotify_helper, priv->route6file_wd);
priv->route6file_wd = -1;
}
}
@ -280,7 +266,9 @@ filename_changed (GObject *object,
if (nm_config_get_monitor_connection_files (nm_config_get ())) {
NMInotifyHelper *ih;
ih = _get_inotify_helper (priv);
if (!priv->inotify_helper)
priv->inotify_helper = g_object_ref (nm_inotify_helper_get ());
ih = priv->inotify_helper;
priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (files_changed_cb), self);
priv->file_wd = nm_inotify_helper_add_watch (ih, ifcfg_path);