mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-31 11:20:12 +01:00
settings: merge branch 'th/drop-monitor-connection-files'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/160
This commit is contained in:
commit
3a1dc8b2f3
11 changed files with 32 additions and 603 deletions
|
|
@ -2839,14 +2839,13 @@ src_settings_plugins_ifcfg_rh_libnms_ifcfg_rh_core_la_SOURCES = \
|
|||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h \
|
||||
src/settings/plugins/ifcfg-rh/shvar.c \
|
||||
src/settings/plugins/ifcfg-rh/shvar.h \
|
||||
src/settings/plugins/ifcfg-rh/nm-inotify-helper.c \
|
||||
src/settings/plugins/ifcfg-rh/nm-inotify-helper.h \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c \
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h
|
||||
src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h \
|
||||
$(NULL)
|
||||
|
||||
src_settings_plugins_ifcfg_rh_libnms_ifcfg_rh_core_la_CPPFLAGS = $(src_cppflags_base)
|
||||
|
||||
|
|
|
|||
4
NEWS
4
NEWS
|
|
@ -16,6 +16,10 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
|
|||
configuration file.
|
||||
* Added support for configuring fq_codel line discipline and mirred action.
|
||||
* Added a possibility for distributions to ship dispatcher scripts in /usr/lib.
|
||||
* Drop deprecated setting "main.monitor-connection-files" in NetworkManager.conf.
|
||||
This setting has no more effect and was disabled by default for a long time.
|
||||
Instead, after changes load files explicitly with `nmcli connection load` and
|
||||
`nmcli connection reload`.
|
||||
|
||||
=============================================
|
||||
NetworkManager-1.18
|
||||
|
|
|
|||
|
|
@ -153,29 +153,7 @@ plugins-=remove-me
|
|||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>monitor-connection-files</varname></term>
|
||||
<listitem><para>Whether the configured settings plugin(s)
|
||||
should set up file monitors and immediately pick up changes
|
||||
made to connection files while NetworkManager is running. This
|
||||
is disabled by default; NetworkManager will only read
|
||||
the connection files at startup, and when explicitly requested
|
||||
via the ReloadConnections D-Bus call. If this key is set to
|
||||
'<literal>true</literal>', then NetworkManager will reload
|
||||
connection files any time they changed.
|
||||
Automatic reloading is not advised because there are race conditions
|
||||
involved and it depends on the way how the editor updates the file.
|
||||
In some situations, NetworkManager might first delete and add the
|
||||
connection anew, instead of updating the existing one. Also, NetworkManager
|
||||
might pick up incomplete settings while the user is still editing the files.
|
||||
</para><para>
|
||||
Note that neither this setting nor restarting the NetworkManager daemon
|
||||
is the advised way to reload connection profiles from disk. Instead, after
|
||||
modifying the files reload them with <command>nmcli connection reload</command>
|
||||
or <command>nmcli connection load "$FILENAME"</command>. Even better,
|
||||
instead of modifying files directly, use NetworkManager tools like
|
||||
<command>nmcli</command>, <command>nmtui</command> or the GUI.
|
||||
</para><para>
|
||||
This setting is deprecated and will have no effect in the future.
|
||||
</para></listitem>
|
||||
<listitem><para>This setting is deprecated and has no effect.</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><varname>auth-polkit</varname></term>
|
||||
|
|
|
|||
|
|
@ -100,8 +100,6 @@ typedef struct {
|
|||
char *no_auto_default_file;
|
||||
char *intern_config_file;
|
||||
|
||||
gboolean monitor_connection_files;
|
||||
|
||||
char *log_level;
|
||||
char *log_domains;
|
||||
|
||||
|
|
@ -313,14 +311,6 @@ nm_config_get_data_orig (NMConfig *config)
|
|||
return NM_CONFIG_GET_PRIVATE (config)->config_data_orig;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_config_get_monitor_connection_files (NMConfig *config)
|
||||
{
|
||||
g_return_val_if_fail (config != NULL, FALSE);
|
||||
|
||||
return NM_CONFIG_GET_PRIVATE (config)->monitor_connection_files;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_config_get_log_level (NMConfig *config)
|
||||
{
|
||||
|
|
@ -2804,10 +2794,6 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
|||
else
|
||||
priv->no_auto_default_file = g_strdup (DEFAULT_NO_AUTO_DEFAULT_FILE);
|
||||
|
||||
priv->monitor_connection_files = nm_config_keyfile_get_boolean (keyfile,
|
||||
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||
NM_CONFIG_KEYFILE_KEY_MAIN_MONITOR_CONNECTION_FILES,
|
||||
FALSE);
|
||||
priv->log_level = nm_strstrip (g_key_file_get_string (keyfile,
|
||||
NM_CONFIG_KEYFILE_GROUP_LOGGING,
|
||||
NM_CONFIG_KEYFILE_KEY_LOGGING_LEVEL,
|
||||
|
|
|
|||
|
|
@ -157,7 +157,6 @@ NMConfigData *nm_config_get_data_orig (NMConfig *config);
|
|||
#define NM_CONFIG_GET_DATA (nm_config_get_data (nm_config_get ()))
|
||||
#define NM_CONFIG_GET_DATA_ORIG (nm_config_get_data_orig (nm_config_get ()))
|
||||
|
||||
gboolean nm_config_get_monitor_connection_files (NMConfig *config);
|
||||
const char *nm_config_get_log_level (NMConfig *config);
|
||||
const char *nm_config_get_log_domains (NMConfig *config);
|
||||
NMConfigConfigureAndQuitType nm_config_get_configure_and_quit (NMConfig *config);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ libnmdbus_ifcfg_rh = static_library(
|
|||
)
|
||||
|
||||
core_sources = files(
|
||||
'nm-inotify-helper.c',
|
||||
'nms-ifcfg-rh-reader.c',
|
||||
'nms-ifcfg-rh-utils.c',
|
||||
'nms-ifcfg-rh-writer.c',
|
||||
|
|
|
|||
|
|
@ -1,213 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager system settings service
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2008 - 2017 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nm-inotify-helper.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/inotify.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
/* NOTE: this code should be killed once we depend on a new enough glib to
|
||||
* include the patches from https://bugzilla.gnome.org/show_bug.cgi?id=532815
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
enum {
|
||||
EVENT,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
typedef struct {
|
||||
int ifd;
|
||||
guint inotify_id;
|
||||
GHashTable *wd_refs;
|
||||
} NMInotifyHelperPrivate;
|
||||
|
||||
struct _NMInotifyHelper {
|
||||
GObject parent;
|
||||
NMInotifyHelperPrivate _priv;
|
||||
};
|
||||
|
||||
struct _NMInotifyHelperClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMInotifyHelper, nm_inotify_helper, G_TYPE_OBJECT)
|
||||
|
||||
#define NM_INOTIFY_HELPER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMInotifyHelper, NM_IS_INOTIFY_HELPER)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_DEFINE_SINGLETON_GETTER (NMInotifyHelper, nm_inotify_helper_get, NM_TYPE_INOTIFY_HELPER);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int
|
||||
nm_inotify_helper_add_watch (NMInotifyHelper *self, const char *path)
|
||||
{
|
||||
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
|
||||
int wd;
|
||||
guint refcount;
|
||||
|
||||
if (priv->ifd < 0)
|
||||
return -1;
|
||||
|
||||
/* We only care about modifications since we're just trying to get change
|
||||
* notifications on hardlinks.
|
||||
*/
|
||||
|
||||
wd = inotify_add_watch (priv->ifd, path, IN_CLOSE_WRITE);
|
||||
if (wd < 0)
|
||||
return -1;
|
||||
|
||||
refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
|
||||
refcount++;
|
||||
g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
|
||||
|
||||
return wd;
|
||||
}
|
||||
|
||||
void
|
||||
nm_inotify_helper_remove_watch (NMInotifyHelper *self, int wd)
|
||||
{
|
||||
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
|
||||
guint refcount;
|
||||
|
||||
if (priv->ifd < 0)
|
||||
return;
|
||||
|
||||
refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
|
||||
if (!refcount)
|
||||
return;
|
||||
|
||||
refcount--;
|
||||
if (!refcount) {
|
||||
g_hash_table_remove (priv->wd_refs, GINT_TO_POINTER (wd));
|
||||
inotify_rm_watch (priv->ifd, wd);
|
||||
} else
|
||||
g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
inotify_event_handler (GIOChannel *channel, GIOCondition cond, gpointer user_data)
|
||||
{
|
||||
NMInotifyHelper *self = NM_INOTIFY_HELPER (user_data);
|
||||
struct inotify_event evt;
|
||||
|
||||
/* read the notifications from the watch descriptor */
|
||||
while (g_io_channel_read_chars (channel, (char *) &evt, sizeof (struct inotify_event), NULL, NULL) == G_IO_STATUS_NORMAL) {
|
||||
char filename[PATH_MAX + 1];
|
||||
|
||||
filename[0] = '\0';
|
||||
if (evt.len > 0) {
|
||||
g_io_channel_read_chars (channel,
|
||||
filename,
|
||||
evt.len > PATH_MAX ? PATH_MAX : evt.len,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
if (!(evt.mask & IN_IGNORED))
|
||||
g_signal_emit (self, signals[EVENT], 0, &evt, &filename[0]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
init_inotify (NMInotifyHelper *self)
|
||||
{
|
||||
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
|
||||
GIOChannel *channel;
|
||||
int errsv;
|
||||
|
||||
priv->ifd = inotify_init1 (IN_CLOEXEC);
|
||||
if (priv->ifd == -1) {
|
||||
errsv = errno;
|
||||
nm_log_warn (LOGD_SETTINGS, "couldn't initialize inotify: %s (%d)", nm_strerror_native (errsv), errsv);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Watch the inotify descriptor for file/directory change events */
|
||||
channel = g_io_channel_unix_new (priv->ifd);
|
||||
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
||||
g_io_channel_set_encoding (channel, NULL, NULL);
|
||||
|
||||
priv->inotify_id = g_io_add_watch (channel,
|
||||
G_IO_IN | G_IO_ERR,
|
||||
(GIOFunc) inotify_event_handler,
|
||||
(gpointer) self);
|
||||
g_io_channel_unref (channel);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nm_inotify_helper_init (NMInotifyHelper *self)
|
||||
{
|
||||
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
|
||||
|
||||
priv->wd_refs = g_hash_table_new (nm_direct_hash, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (nm_inotify_helper_parent_class)->constructed (object);
|
||||
|
||||
init_inotify (NM_INOTIFY_HELPER (object));
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE ((NMInotifyHelper *) object);
|
||||
|
||||
nm_clear_g_source (&priv->inotify_id);
|
||||
nm_close (priv->ifd);
|
||||
|
||||
g_hash_table_destroy (priv->wd_refs);
|
||||
|
||||
G_OBJECT_CLASS (nm_inotify_helper_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_inotify_helper_class_init (NMInotifyHelperClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->constructed = constructed;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
signals[EVENT] =
|
||||
g_signal_new ("event",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_STRING);
|
||||
}
|
||||
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager system settings service
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2008 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __NM_INOTIFY_HELPER_H__
|
||||
#define __NM_INOTIFY_HELPER_H__
|
||||
|
||||
/* NOTE: this code should be killed once we depend on a new enough glib to
|
||||
* include the patches from https://bugzilla.gnome.org/show_bug.cgi?id=532815
|
||||
*/
|
||||
|
||||
#define NM_TYPE_INOTIFY_HELPER (nm_inotify_helper_get_type ())
|
||||
#define NM_INOTIFY_HELPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelper))
|
||||
#define NM_INOTIFY_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
|
||||
#define NM_IS_INOTIFY_HELPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_INOTIFY_HELPER))
|
||||
#define NM_IS_INOTIFY_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_INOTIFY_HELPER))
|
||||
#define NM_INOTIFY_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
|
||||
|
||||
typedef struct _NMInotifyHelper NMInotifyHelper;
|
||||
typedef struct _NMInotifyHelperClass NMInotifyHelperClass;
|
||||
|
||||
GType nm_inotify_helper_get_type (void);
|
||||
|
||||
NMInotifyHelper * nm_inotify_helper_get (void);
|
||||
|
||||
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__ */
|
||||
|
|
@ -41,7 +41,6 @@
|
|||
#include "nms-ifcfg-rh-reader.h"
|
||||
#include "nms-ifcfg-rh-writer.h"
|
||||
#include "nms-ifcfg-rh-utils.h"
|
||||
#include "nm-inotify-helper.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -50,34 +49,12 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
|||
PROP_UNRECOGNIZED_SPEC,
|
||||
);
|
||||
|
||||
enum {
|
||||
IFCFG_CHANGED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
typedef struct {
|
||||
gulong ih_event_id;
|
||||
|
||||
int file_wd;
|
||||
|
||||
char *keyfile;
|
||||
int keyfile_wd;
|
||||
|
||||
char *routefile;
|
||||
int routefile_wd;
|
||||
|
||||
char *route6file;
|
||||
int route6file_wd;
|
||||
|
||||
char *unmanaged_spec;
|
||||
char *unrecognized_spec;
|
||||
|
||||
gulong devtimeout_link_changed_handler;
|
||||
guint devtimeout_timeout_id;
|
||||
|
||||
NMInotifyHelper *inotify_helper;
|
||||
} NMIfcfgConnectionPrivate;
|
||||
|
||||
struct _NMIfcfgConnection {
|
||||
|
|
@ -193,76 +170,6 @@ nm_ifcfg_connection_check_devtimeout (NMIfcfgConnection *self)
|
|||
priv->devtimeout_timeout_id = g_timeout_add_seconds (devtimeout, devtimeout_expired, self);
|
||||
}
|
||||
|
||||
static void
|
||||
files_changed_cb (NMInotifyHelper *ih,
|
||||
struct inotify_event *evt,
|
||||
const char *path,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMIfcfgConnection *self = NM_IFCFG_CONNECTION (user_data);
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
if ( (evt->wd != priv->file_wd)
|
||||
&& (evt->wd != priv->keyfile_wd)
|
||||
&& (evt->wd != priv->routefile_wd)
|
||||
&& (evt->wd != priv->route6file_wd))
|
||||
return;
|
||||
|
||||
/* push the event up to the plugin */
|
||||
g_signal_emit (self, signals[IFCFG_CHANGED], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
path_watch_stop (NMIfcfgConnection *self)
|
||||
{
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
|
||||
|
||||
nm_clear_g_signal_handler (priv->inotify_helper, &priv->ih_event_id);
|
||||
|
||||
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);
|
||||
nm_clear_g_free (&priv->routefile);
|
||||
nm_clear_g_free (&priv->route6file);
|
||||
}
|
||||
|
||||
static void
|
||||
filename_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMIfcfgConnection *self = NM_IFCFG_CONNECTION (object);
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self);
|
||||
const char *ifcfg_path;
|
||||
|
||||
path_watch_stop (self);
|
||||
|
||||
ifcfg_path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (self));
|
||||
if (!ifcfg_path)
|
||||
return;
|
||||
|
||||
priv->keyfile = utils_get_keys_path (ifcfg_path);
|
||||
priv->routefile = utils_get_route_path (ifcfg_path);
|
||||
priv->route6file = utils_get_route6_path (ifcfg_path);
|
||||
|
||||
if (nm_config_get_monitor_connection_files (nm_config_get ())) {
|
||||
NMInotifyHelper *ih;
|
||||
|
||||
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);
|
||||
priv->keyfile_wd = nm_inotify_helper_add_watch (ih, priv->keyfile);
|
||||
priv->routefile_wd = nm_inotify_helper_add_watch (ih, priv->routefile);
|
||||
priv->route6file_wd = nm_inotify_helper_add_watch (ih, priv->route6file);
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_ifcfg_connection_get_unmanaged_spec (NMIfcfgConnection *self)
|
||||
{
|
||||
|
|
@ -326,18 +233,21 @@ static gboolean
|
|||
delete (NMSettingsConnection *connection,
|
||||
GError **error)
|
||||
{
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) connection);
|
||||
const char *filename;
|
||||
|
||||
filename = nm_settings_connection_get_filename (connection);
|
||||
if (filename) {
|
||||
gs_free char *keyfile = utils_get_keys_path (filename);
|
||||
gs_free char *routefile = utils_get_route_path (filename);
|
||||
gs_free char *route6file = utils_get_route6_path (filename);
|
||||
|
||||
g_unlink (filename);
|
||||
if (priv->keyfile)
|
||||
g_unlink (priv->keyfile);
|
||||
if (priv->routefile)
|
||||
g_unlink (priv->routefile);
|
||||
if (priv->route6file)
|
||||
g_unlink (priv->route6file);
|
||||
if (keyfile)
|
||||
g_unlink (keyfile);
|
||||
if (routefile)
|
||||
g_unlink (routefile);
|
||||
if (route6file)
|
||||
g_unlink (route6file);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
@ -386,17 +296,8 @@ set_property (GObject *object, guint prop_id,
|
|||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nm_ifcfg_connection_init (NMIfcfgConnection *connection)
|
||||
nm_ifcfg_connection_init (NMIfcfgConnection *self)
|
||||
{
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (connection);
|
||||
|
||||
priv->file_wd = -1;
|
||||
priv->keyfile_wd = -1;
|
||||
priv->routefile_wd = -1;
|
||||
priv->route6file_wd = -1;
|
||||
|
||||
g_signal_connect (connection, "notify::" NM_SETTINGS_CONNECTION_FILENAME,
|
||||
G_CALLBACK (filename_changed), NULL);
|
||||
}
|
||||
|
||||
NMIfcfgConnection *
|
||||
|
|
@ -460,13 +361,9 @@ dispose (GObject *object)
|
|||
{
|
||||
NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE ((NMIfcfgConnection *) object);
|
||||
|
||||
path_watch_stop (NM_IFCFG_CONNECTION (object));
|
||||
|
||||
nm_clear_g_signal_handler (NM_PLATFORM_GET, &priv->devtimeout_link_changed_handler);
|
||||
nm_clear_g_source (&priv->devtimeout_timeout_id);
|
||||
|
||||
g_clear_object (&priv->inotify_helper);
|
||||
|
||||
g_clear_pointer (&priv->unmanaged_spec, g_free);
|
||||
g_clear_pointer (&priv->unrecognized_spec, g_free);
|
||||
|
||||
|
|
@ -499,13 +396,4 @@ nm_ifcfg_connection_class_init (NMIfcfgConnectionClass *ifcfg_connection_class)
|
|||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
signals[IFCFG_CHANGED] =
|
||||
g_signal_new ("ifcfg-changed",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,10 +61,8 @@ typedef struct {
|
|||
} dbus;
|
||||
|
||||
GHashTable *connections; /* uuid::connection */
|
||||
gboolean initialized;
|
||||
|
||||
GFileMonitor *ifcfg_monitor;
|
||||
gulong ifcfg_monitor_id;
|
||||
bool initialized:1;
|
||||
} SettingsPluginIfcfgPrivate;
|
||||
|
||||
struct _SettingsPluginIfcfg {
|
||||
|
|
@ -109,26 +107,6 @@ static NMIfcfgConnection *update_connection (SettingsPluginIfcfg *plugin,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
connection_ifcfg_changed (NMIfcfgConnection *connection, gpointer user_data)
|
||||
{
|
||||
SettingsPluginIfcfg *self = SETTINGS_PLUGIN_IFCFG (user_data);
|
||||
SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self);
|
||||
const char *path;
|
||||
|
||||
path = nm_settings_connection_get_filename (NM_SETTINGS_CONNECTION (connection));
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
if (!priv->ifcfg_monitor) {
|
||||
_LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "ignore event");
|
||||
return;
|
||||
}
|
||||
|
||||
_LOGD ("connection_ifcfg_changed("NM_IFCFG_CONNECTION_LOG_FMTD"): %s", NM_IFCFG_CONNECTION_LOG_ARGD (connection), "reload");
|
||||
|
||||
update_connection (self, NULL, path, connection, TRUE, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
|
||||
{
|
||||
|
|
@ -386,10 +364,6 @@ update_connection (SettingsPluginIfcfg *self,
|
|||
} else if (nm_ifcfg_connection_get_unrecognized_spec (connection_new))
|
||||
_LOGW ("Ignoring connection "NM_IFCFG_CONNECTION_LOG_FMT" of unrecognized type.", NM_IFCFG_CONNECTION_LOG_ARG (connection_new));
|
||||
|
||||
/* watch changes of ifcfg hardlinks */
|
||||
g_signal_connect (G_OBJECT (connection_new), "ifcfg-changed",
|
||||
G_CALLBACK (connection_ifcfg_changed), self);
|
||||
|
||||
if (!source) {
|
||||
/* Only raise the signal if we were called without source, i.e. if we read the connection from file.
|
||||
* Otherwise, we were called by add_connection() which does not expect the signal. */
|
||||
|
|
@ -406,59 +380,6 @@ update_connection (SettingsPluginIfcfg *self,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ifcfg_dir_changed (GFileMonitor *monitor,
|
||||
GFile *file,
|
||||
GFile *other_file,
|
||||
GFileMonitorEvent event_type,
|
||||
gpointer user_data)
|
||||
{
|
||||
SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (user_data);
|
||||
char *path, *ifcfg_path;
|
||||
NMIfcfgConnection *connection;
|
||||
|
||||
path = g_file_get_path (file);
|
||||
|
||||
ifcfg_path = utils_detect_ifcfg_path (path, FALSE);
|
||||
_LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ?: "(none)");
|
||||
if (ifcfg_path) {
|
||||
connection = find_by_path (plugin, ifcfg_path);
|
||||
switch (event_type) {
|
||||
case G_FILE_MONITOR_EVENT_DELETED:
|
||||
if (connection)
|
||||
remove_connection (plugin, connection);
|
||||
break;
|
||||
case G_FILE_MONITOR_EVENT_CREATED:
|
||||
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
||||
/* Update or new */
|
||||
update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
g_free (ifcfg_path);
|
||||
}
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
static void
|
||||
setup_ifcfg_monitoring (SettingsPluginIfcfg *plugin)
|
||||
{
|
||||
SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (plugin);
|
||||
GFile *file;
|
||||
GFileMonitor *monitor;
|
||||
|
||||
file = g_file_new_for_path (IFCFG_DIR "/");
|
||||
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
if (monitor) {
|
||||
priv->ifcfg_monitor_id = g_signal_connect (monitor, "changed",
|
||||
G_CALLBACK (ifcfg_dir_changed), plugin);
|
||||
priv->ifcfg_monitor = monitor;
|
||||
}
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
_paths_from_connections (GHashTable *connections)
|
||||
{
|
||||
|
|
@ -578,8 +499,6 @@ get_connections (NMSettingsPlugin *config)
|
|||
NMIfcfgConnection *connection;
|
||||
|
||||
if (!priv->initialized) {
|
||||
if (nm_config_get_monitor_connection_files (nm_config_get ()))
|
||||
setup_ifcfg_monitoring (plugin);
|
||||
read_connections (plugin);
|
||||
priv->initialized = TRUE;
|
||||
}
|
||||
|
|
@ -1041,14 +960,6 @@ dispose (GObject *object)
|
|||
priv->connections = NULL;
|
||||
}
|
||||
|
||||
if (priv->ifcfg_monitor) {
|
||||
if (priv->ifcfg_monitor_id)
|
||||
g_signal_handler_disconnect (priv->ifcfg_monitor, priv->ifcfg_monitor_id);
|
||||
|
||||
g_file_monitor_cancel (priv->ifcfg_monitor);
|
||||
g_object_unref (priv->ifcfg_monitor);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (settings_plugin_ifcfg_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,6 @@ typedef struct {
|
|||
GHashTable *connections; /* uuid::connection */
|
||||
|
||||
gboolean initialized;
|
||||
GFileMonitor *monitor;
|
||||
gulong monitor_id;
|
||||
|
||||
NMConfig *config;
|
||||
} NMSKeyfilePluginPrivate;
|
||||
|
|
@ -297,47 +295,6 @@ update_connection (NMSKeyfilePlugin *self,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dir_changed (GFileMonitor *monitor,
|
||||
GFile *file,
|
||||
GFile *other_file,
|
||||
GFileMonitorEvent event_type,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMSettingsPlugin *config = NM_SETTINGS_PLUGIN (user_data);
|
||||
NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config);
|
||||
NMSKeyfileConnection *connection;
|
||||
char *full_path;
|
||||
gboolean exists;
|
||||
|
||||
full_path = g_file_get_path (file);
|
||||
if (nm_keyfile_utils_ignore_filename (full_path, FALSE)) {
|
||||
g_free (full_path);
|
||||
return;
|
||||
}
|
||||
exists = g_file_test (full_path, G_FILE_TEST_EXISTS);
|
||||
|
||||
_LOGD ("dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist");
|
||||
|
||||
connection = find_by_path (self, full_path);
|
||||
|
||||
switch (event_type) {
|
||||
case G_FILE_MONITOR_EVENT_DELETED:
|
||||
if (!exists && connection)
|
||||
remove_connection (NMS_KEYFILE_PLUGIN (config), connection);
|
||||
break;
|
||||
case G_FILE_MONITOR_EVENT_CREATED:
|
||||
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
||||
if (exists)
|
||||
update_connection (NMS_KEYFILE_PLUGIN (config), NULL, full_path, connection, TRUE, NULL, NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (full_path);
|
||||
}
|
||||
|
||||
static void
|
||||
config_changed_cb (NMConfig *config,
|
||||
NMConfigData *config_data,
|
||||
|
|
@ -355,30 +312,6 @@ config_changed_cb (NMConfig *config,
|
|||
_nm_settings_plugin_emit_signal_unmanaged_specs_changed (NM_SETTINGS_PLUGIN (self));
|
||||
}
|
||||
|
||||
static void
|
||||
setup_monitoring (NMSettingsPlugin *config)
|
||||
{
|
||||
NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config);
|
||||
GFile *file;
|
||||
GFileMonitor *monitor;
|
||||
|
||||
if (nm_config_get_monitor_connection_files (priv->config)) {
|
||||
file = g_file_new_for_path (nms_keyfile_utils_get_path ());
|
||||
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
g_object_unref (file);
|
||||
|
||||
if (monitor) {
|
||||
priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), config);
|
||||
priv->monitor = monitor;
|
||||
}
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT (priv->config),
|
||||
NM_CONFIG_SIGNAL_CONFIG_CHANGED,
|
||||
G_CALLBACK (config_changed_cb),
|
||||
config);
|
||||
}
|
||||
|
||||
static GHashTable *
|
||||
_paths_from_connections (GHashTable *connections)
|
||||
{
|
||||
|
|
@ -504,7 +437,6 @@ get_connections (NMSettingsPlugin *config)
|
|||
NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) config);
|
||||
|
||||
if (!priv->initialized) {
|
||||
setup_monitoring (config);
|
||||
read_connections (config);
|
||||
priv->initialized = TRUE;
|
||||
}
|
||||
|
|
@ -590,7 +522,8 @@ nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin)
|
|||
static void
|
||||
constructed (GObject *object)
|
||||
{
|
||||
NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object);
|
||||
NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (object);
|
||||
NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (self);
|
||||
|
||||
G_OBJECT_CLASS (nms_keyfile_plugin_parent_class)->constructed (object);
|
||||
|
||||
|
|
@ -599,6 +532,17 @@ constructed (GObject *object)
|
|||
NM_CONFIG_KEYFILE_KEY_KEYFILE_HOSTNAME,
|
||||
NM_CONFIG_GET_VALUE_RAW))
|
||||
_LOGW ("'hostname' option is deprecated and has no effect");
|
||||
|
||||
if (nm_config_data_has_value (nm_config_get_data_orig (priv->config),
|
||||
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
||||
NM_CONFIG_KEYFILE_KEY_MAIN_MONITOR_CONNECTION_FILES,
|
||||
NM_CONFIG_GET_VALUE_RAW))
|
||||
_LOGW ("'monitor-connection-files' option is deprecated and has no effect");
|
||||
|
||||
g_signal_connect (G_OBJECT (priv->config),
|
||||
NM_CONFIG_SIGNAL_CONFIG_CHANGED,
|
||||
G_CALLBACK (config_changed_cb),
|
||||
self);
|
||||
}
|
||||
|
||||
NMSKeyfilePlugin *
|
||||
|
|
@ -612,13 +556,6 @@ dispose (GObject *object)
|
|||
{
|
||||
NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE ((NMSKeyfilePlugin *) object);
|
||||
|
||||
if (priv->monitor) {
|
||||
nm_clear_g_signal_handler (priv->monitor, &priv->monitor_id);
|
||||
|
||||
g_file_monitor_cancel (priv->monitor);
|
||||
g_clear_object (&priv->monitor);
|
||||
}
|
||||
|
||||
if (priv->connections) {
|
||||
g_hash_table_destroy (priv->connections);
|
||||
priv->connections = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue