From 652853e0d0749a12db07e34f1a3cd901020a76f8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 19 Feb 2015 14:24:37 +0100 Subject: [PATCH] connectivity: use default on missing connectivity.interval config Manual page claims that a missing configuration option for connectivity interval means "300". That was not the case for a long time (never?). https://bugzilla.gnome.org/show_bug.cgi?id=723350 Based-on-patch-by: Mathieu Trudel-Lapierre --- src/nm-config-data.c | 12 +++++++++--- src/nm-config.h | 2 ++ src/nm-connectivity.c | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/nm-config-data.c b/src/nm-config-data.c index f624862a6d..2142670ba5 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -26,6 +26,7 @@ #include "nm-config.h" #include "gsystem-local-alloc.h" #include "nm-device.h" +#include "nm-core-internal.h" typedef struct { char *config_main_file; @@ -343,13 +344,18 @@ constructed (GObject *object) { NMConfigData *self = NM_CONFIG_DATA (object); NMConfigDataPrivate *priv = NM_CONFIG_DATA_GET_PRIVATE (self); - int interval; + char *interval; priv->connectivity.uri = g_key_file_get_value (priv->keyfile, "connectivity", "uri", NULL); priv->connectivity.response = g_key_file_get_value (priv->keyfile, "connectivity", "response", NULL); - interval = g_key_file_get_integer (priv->keyfile, "connectivity", "interval", NULL); - priv->connectivity.interval = MAX (0, interval); + /* On missing config value, fallback to 300. On invalid value, disable connectivity checking by setting + * the interval to zero. */ + interval = g_key_file_get_value (priv->keyfile, "connectivity", "interval", NULL); + priv->connectivity.interval = interval + ? _nm_utils_ascii_str_to_int64 (interval, 10, 0, G_MAXUINT, 0) + : NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL; + g_free (interval); priv->dns_mode = g_key_file_get_value (priv->keyfile, "main", "dns", NULL); priv->rc_manager = g_key_file_get_value (priv->keyfile, "main", "rc-manager", NULL); diff --git a/src/nm-config.h b/src/nm-config.h index ecd083a62c..e72132af9d 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -43,6 +43,8 @@ G_BEGIN_DECLS /* Signals */ #define NM_CONFIG_SIGNAL_CONFIG_CHANGED "config-changed" +#define NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL 300 + typedef struct NMConfigCmdLineOptions NMConfigCmdLineOptions; struct _NMConfig { diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index ecb9c0f5c1..1dfcf00b15 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -27,6 +27,7 @@ #endif #include "nm-connectivity.h" +#include "nm-config.h" #include "nm-logging.h" G_DEFINE_TYPE (NMConnectivity, nm_connectivity, G_TYPE_OBJECT) @@ -499,7 +500,7 @@ nm_connectivity_class_init (NMConnectivityClass *klass) g_object_class_install_property (object_class, PROP_INTERVAL, g_param_spec_uint (NM_CONNECTIVITY_INTERVAL, "", "", - 0, G_MAXUINT, 300, + 0, G_MAXUINT, NM_CONFIG_DEFAULT_CONNECTIVITY_INTERVAL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));