config: pass signals to nm_config_reload()
Also react on SIGUSR1 and SIGUSR2, beside SIGHUP. Only for SIGHUP actually reload the configuration from disc. For the other signals only emit a config-changed signal.
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
static gboolean
|
||||
sighup_handler (gpointer user_data)
|
||||
{
|
||||
nm_main_config_reload ();
|
||||
nm_main_config_reload (GPOINTER_TO_INT (user_data));
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
@@ -83,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__ */
|
||||
|
@@ -205,16 +205,16 @@ _init_nm_debug (const char *debug)
|
||||
}
|
||||
|
||||
void
|
||||
nm_main_config_reload ()
|
||||
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,12 +47,17 @@ 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_RC_MANAGER = (1L << 5),
|
||||
|
||||
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_RC_MANAGER = (1L << 8),
|
||||
|
||||
_NM_CONFIG_CHANGE_LAST,
|
||||
NM_CONFIG_CHANGE_ALL = ((_NM_CONFIG_CHANGE_LAST - 1) << 1) - 1,
|
||||
|
@@ -104,7 +104,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);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -316,7 +316,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);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@@ -677,7 +677,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;
|
||||
@@ -690,6 +690,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.
|
||||
@@ -702,6 +707,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);
|
||||
@@ -709,13 +715,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:
|
||||
@@ -752,24 +764,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,
|
||||
|
@@ -500,7 +500,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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user