mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 14:40:08 +01:00
config,dns: merge branch 'th/dns-update-on-sigusr1-rh1062301'
https://bugzilla.redhat.com/show_bug.cgi?id=1062301
(cherry picked from commit 7bf78d9511)
This commit is contained in:
commit
a12bc0060f
8 changed files with 85 additions and 37 deletions
|
|
@ -1141,14 +1141,16 @@ config_changed_cb (NMConfig *config,
|
|||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!(changes & NM_CONFIG_CHANGE_DNS_MODE))
|
||||
return;
|
||||
if (NM_FLAGS_HAS (changes, NM_CONFIG_CHANGE_DNS_MODE))
|
||||
init_resolv_conf_mode (self);
|
||||
|
||||
init_resolv_conf_mode (self);
|
||||
if (!update_dns (self, TRUE, &error)) {
|
||||
nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
|
||||
error->code, error->message);
|
||||
g_clear_error (&error);
|
||||
if (NM_FLAGS_ANY (changes, NM_CONFIG_CHANGE_SIGHUP |
|
||||
NM_CONFIG_CHANGE_SIGUSR1 |
|
||||
NM_CONFIG_CHANGE_DNS_MODE)) {
|
||||
if (!update_dns (self, TRUE, &error)) {
|
||||
nm_log_warn (LOGD_DNS, "could not commit DNS changes: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,9 +44,7 @@
|
|||
static gboolean
|
||||
sighup_handler (gpointer user_data)
|
||||
{
|
||||
/* Reread config stuff like system config files, VPN service files, etc */
|
||||
nm_main_config_reload ();
|
||||
|
||||
nm_main_config_reload (GPOINTER_TO_INT (user_data));
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +83,9 @@ nm_main_utils_setup_signals (GMainLoop *main_loop)
|
|||
|
||||
signal (SIGPIPE, SIG_IGN);
|
||||
|
||||
g_unix_signal_add (SIGHUP, sighup_handler, NULL);
|
||||
g_unix_signal_add (SIGHUP, sighup_handler, GINT_TO_POINTER (SIGHUP));
|
||||
g_unix_signal_add (SIGUSR1, sighup_handler, GINT_TO_POINTER (SIGUSR1));
|
||||
g_unix_signal_add (SIGUSR2, sighup_handler, GINT_TO_POINTER (SIGUSR2));
|
||||
g_unix_signal_add (SIGINT, sigint_handler, main_loop);
|
||||
g_unix_signal_add (SIGTERM, sigterm_handler, main_loop);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ gboolean nm_main_utils_early_setup (const char *progname,
|
|||
/* The following functions are not implemented inside nm-main-utils.c, instead
|
||||
* main.c and nm-iface-helper.c */
|
||||
|
||||
void nm_main_config_reload (void);
|
||||
void nm_main_config_reload (int signal);
|
||||
|
||||
#endif /* __MAIN_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -208,16 +208,16 @@ _init_nm_debug (const char *debug)
|
|||
}
|
||||
|
||||
void
|
||||
nm_main_config_reload (void)
|
||||
nm_main_config_reload (int signal)
|
||||
{
|
||||
nm_log_info (LOGD_CORE, "reload configuration...");
|
||||
nm_log_info (LOGD_CORE, "reload configuration (signal %s)...", strsignal (signal));
|
||||
/* The signal handler thread is only installed after
|
||||
* creating NMConfig instance, and on shut down we
|
||||
* no longer run the mainloop (to reach this point).
|
||||
*
|
||||
* Hence, a NMConfig singleton instance must always be
|
||||
* available. */
|
||||
nm_config_reload (nm_config_get ());
|
||||
nm_config_reload (nm_config_get (), signal);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -47,11 +47,16 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef enum { /*< flags >*/
|
||||
NM_CONFIG_CHANGE_NONE = 0,
|
||||
NM_CONFIG_CHANGE_CONFIG_FILES = (1L << 0),
|
||||
NM_CONFIG_CHANGE_VALUES = (1L << 1),
|
||||
NM_CONFIG_CHANGE_CONNECTIVITY = (1L << 2),
|
||||
NM_CONFIG_CHANGE_NO_AUTO_DEFAULT = (1L << 3),
|
||||
NM_CONFIG_CHANGE_DNS_MODE = (1L << 4),
|
||||
|
||||
NM_CONFIG_CHANGE_SIGHUP = (1L << 0),
|
||||
NM_CONFIG_CHANGE_SIGUSR1 = (1L << 1),
|
||||
NM_CONFIG_CHANGE_SIGUSR2 = (1L << 2),
|
||||
|
||||
NM_CONFIG_CHANGE_CONFIG_FILES = (1L << 3),
|
||||
NM_CONFIG_CHANGE_VALUES = (1L << 4),
|
||||
NM_CONFIG_CHANGE_CONNECTIVITY = (1L << 5),
|
||||
NM_CONFIG_CHANGE_NO_AUTO_DEFAULT = (1L << 6),
|
||||
NM_CONFIG_CHANGE_DNS_MODE = (1L << 7),
|
||||
|
||||
_NM_CONFIG_CHANGE_LAST,
|
||||
NM_CONFIG_CHANGE_ALL = ((_NM_CONFIG_CHANGE_LAST - 1) << 1) - 1,
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ G_DEFINE_TYPE_WITH_CODE (NMConfig, nm_config, G_TYPE_OBJECT,
|
|||
|
||||
/************************************************************************/
|
||||
|
||||
static void _set_config_data (NMConfig *self, NMConfigData *new_data);
|
||||
static void _set_config_data (NMConfig *self, NMConfigData *new_data, int signal);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
|
|
@ -315,7 +315,7 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
|
|||
new_data = nm_config_data_new_update_no_auto_default (priv->config_data, (const char *const*) no_auto_default);
|
||||
g_strfreev (no_auto_default);
|
||||
|
||||
_set_config_data (self, new_data);
|
||||
_set_config_data (self, new_data, 0);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
|
@ -670,7 +670,7 @@ nm_config_get_device_match_spec (const GKeyFile *keyfile, const char *group, con
|
|||
/************************************************************************/
|
||||
|
||||
void
|
||||
nm_config_reload (NMConfig *self)
|
||||
nm_config_reload (NMConfig *self, int signal)
|
||||
{
|
||||
NMConfigPrivate *priv;
|
||||
GError *error = NULL;
|
||||
|
|
@ -683,6 +683,11 @@ nm_config_reload (NMConfig *self)
|
|||
|
||||
priv = NM_CONFIG_GET_PRIVATE (self);
|
||||
|
||||
if (signal != SIGHUP) {
|
||||
_set_config_data (self, NULL, signal);
|
||||
return;
|
||||
}
|
||||
|
||||
/* pass on the original command line options. This means, that
|
||||
* options specified at command line cannot ever be reloaded from
|
||||
* file. That seems desirable.
|
||||
|
|
@ -695,6 +700,7 @@ nm_config_reload (NMConfig *self)
|
|||
if (!keyfile) {
|
||||
nm_log_err (LOGD_CORE, "Failed to reload the configuration: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
_set_config_data (self, NULL, signal);
|
||||
return;
|
||||
}
|
||||
new_data = nm_config_data_new (config_main_file, config_description, nm_config_data_get_no_auto_default (priv->config_data), keyfile);
|
||||
|
|
@ -702,13 +708,19 @@ nm_config_reload (NMConfig *self)
|
|||
g_free (config_description);
|
||||
g_key_file_unref (keyfile);
|
||||
|
||||
_set_config_data (self, new_data);
|
||||
_set_config_data (self, new_data, signal);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_change_flags_one_to_string (NMConfigChangeFlags flag)
|
||||
{
|
||||
switch (flag) {
|
||||
case NM_CONFIG_CHANGE_SIGHUP:
|
||||
return "SIGHUP";
|
||||
case NM_CONFIG_CHANGE_SIGUSR1:
|
||||
return "SIGUSR1";
|
||||
case NM_CONFIG_CHANGE_SIGUSR2:
|
||||
return "SIGUSR2";
|
||||
case NM_CONFIG_CHANGE_CONFIG_FILES:
|
||||
return "config-files";
|
||||
case NM_CONFIG_CHANGE_VALUES:
|
||||
|
|
@ -743,24 +755,53 @@ nm_config_change_flags_to_string (NMConfigChangeFlags flags)
|
|||
}
|
||||
|
||||
static void
|
||||
_set_config_data (NMConfig *self, NMConfigData *new_data)
|
||||
_set_config_data (NMConfig *self, NMConfigData *new_data, int signal)
|
||||
{
|
||||
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (self);
|
||||
NMConfigData *old_data = priv->config_data;
|
||||
NMConfigChangeFlags changes;
|
||||
NMConfigChangeFlags changes, changes_diff;
|
||||
gs_free char *log_str = NULL;
|
||||
gboolean had_new_data = !!new_data;
|
||||
|
||||
changes = nm_config_data_diff (old_data, new_data);
|
||||
if (changes == NM_CONFIG_CHANGE_NONE) {
|
||||
g_object_unref (new_data);
|
||||
return;
|
||||
switch (signal) {
|
||||
case SIGHUP:
|
||||
changes = NM_CONFIG_CHANGE_SIGHUP;
|
||||
break;
|
||||
case SIGUSR1:
|
||||
changes = NM_CONFIG_CHANGE_SIGUSR1;
|
||||
break;
|
||||
case SIGUSR2:
|
||||
changes = NM_CONFIG_CHANGE_SIGUSR2;
|
||||
break;
|
||||
default:
|
||||
changes = NM_CONFIG_CHANGE_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
nm_log_info (LOGD_CORE, "config: update %s (%s)", nm_config_data_get_config_description (new_data),
|
||||
(log_str = nm_config_change_flags_to_string (changes)));
|
||||
priv->config_data = new_data;
|
||||
g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0, new_data, changes, old_data);
|
||||
g_object_unref (old_data);
|
||||
if (new_data) {
|
||||
changes_diff = nm_config_data_diff (old_data, new_data);
|
||||
if (changes_diff == NM_CONFIG_CHANGE_NONE)
|
||||
g_clear_object (&new_data);
|
||||
else
|
||||
changes |= changes_diff;
|
||||
}
|
||||
|
||||
if (changes == NM_CONFIG_CHANGE_NONE)
|
||||
return;
|
||||
|
||||
if (new_data) {
|
||||
nm_log_info (LOGD_CORE, "config: update %s (%s)", nm_config_data_get_config_description (new_data),
|
||||
(log_str = nm_config_change_flags_to_string (changes)));
|
||||
priv->config_data = new_data;
|
||||
} else if (had_new_data)
|
||||
nm_log_info (LOGD_CORE, "config: signal %s (no changes from disk)", (log_str = nm_config_change_flags_to_string (changes)));
|
||||
else
|
||||
nm_log_info (LOGD_CORE, "config: signal %s", (log_str = nm_config_change_flags_to_string (changes)));
|
||||
g_signal_emit (self, signals[SIGNAL_CONFIG_CHANGED], 0,
|
||||
new_data ? new_data : old_data,
|
||||
changes, old_data);
|
||||
if (new_data)
|
||||
g_object_unref (old_data);
|
||||
}
|
||||
|
||||
NM_DEFINE_SINGLETON_DESTRUCTOR (NMConfig);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ void nm_config_set_no_auto_default_for_device (NMConfig *config, NMDevice *devi
|
|||
|
||||
NMConfig *nm_config_new (const NMConfigCmdLineOptions *cli, GError **error);
|
||||
NMConfig *nm_config_setup (const NMConfigCmdLineOptions *cli, GError **error);
|
||||
void nm_config_reload (NMConfig *config);
|
||||
void nm_config_reload (NMConfig *config, int signal);
|
||||
|
||||
GKeyFile *nm_config_create_keyfile (void);
|
||||
gboolean nm_config_keyfile_get_boolean (GKeyFile *keyfile,
|
||||
|
|
|
|||
|
|
@ -501,7 +501,7 @@ main (int argc, char *argv[])
|
|||
/* Stub functions */
|
||||
|
||||
void
|
||||
nm_main_config_reload ()
|
||||
nm_main_config_reload (int signal)
|
||||
{
|
||||
nm_log_info (LOGD_CORE, "reloading configuration not supported");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue