Re: PATCH: Add stub mode



On Thu, 2012-07-19 at 11:48 -0400, Ross Vandegrift wrote:
> Hello all,
> 
> My workstation's network setup is beyond the use-case that NM covers,
> and so NM doesn't have any interfaces to manage.  I'd disable it, but
> an increasing number of apps refuse to do anything if NM doesn't report
> that we're online.  I couldn't find a central way to disable this, so I
> implemented one.

Those apps are buggy if they refuse to do anything, but NetworkManager
isn't actually running.  What apps are these?

Dan

> Stub mode forces reporting that we have global connectivity.  It must
> be explicitly enabled by the user, and it doesn't interfere with any
> device management.
> 
> Patch below is against 0.9.5.95 (772d03fa).  It works well enough to
> get evolution, pidgin, iceweasel, etc to go ahead and do their jobs.
> 
> Ross
> 
> 
>  man/NetworkManager.conf.5.in |    5 +++++
>  src/main.c                   |    5 ++++-
>  src/nm-config.c              |   21 ++++++++++++++++++---
>  src/nm-config.h              |    2 ++
>  src/nm-manager.c             |   18 ++++++++++++++++++
>  src/nm-manager.h             |    1 +
>  6 files changed, 48 insertions(+), 4 deletions(-)
> 
> diff --git a/man/NetworkManager.conf.5.in b/man/NetworkManager.conf.5.in
> index 84b4d75..c53dc7d 100644
> --- a/man/NetworkManager.conf.5.in
> +++ b/man/NetworkManager.conf.5.in
> @@ -231,6 +231,11 @@ seconds.
>  .B response=\fI<response>\fP
>  If set controls what body content NetworkManager checks for when requesting the
>  URI for connectivity checking.  If missing, defaults to "NetworkManager is online"
> +.TP
> +.B stub=\fI<true>\fP
> +If set to true, NetworkManager will artificially force the network state to
> +appear globally connected.  Only useful on systems where connectivity is managed
> +by some other means, but which also require using apps that rely on NetworkManager.
>  .SH "SEE ALSO"
>  .BR http://live.gnome.org/NetworkManager/SystemSettings
>  .sp
> diff --git a/src/main.c b/src/main.c
> index e8ff2e4..aa83fee 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -357,6 +357,7 @@ main (int argc, char *argv[])
>  	char *connectivity_uri = NULL;
>  	gint connectivity_interval = -1;
>  	char *connectivity_response = NULL;
> +	gboolean connectivity_stub = FALSE;
>  	gboolean wifi_enabled = TRUE, net_enabled = TRUE, wwan_enabled = TRUE, wimax_enabled = TRUE;
>  	gboolean success, show_version = FALSE;
>  	NMPolicy *policy = NULL;
> @@ -393,6 +394,7 @@ main (int argc, char *argv[])
>  		{ "connectivity-uri", 0, 0, G_OPTION_ARG_STRING, &connectivity_uri, "A http(s) address to check internet connectivity" },
>  		{ "connectivity-interval", 0, 0, G_OPTION_ARG_INT, &connectivity_interval, "the interval in seconds how often a connectivity check will be done" },
>  		{ "connectivity-response", 0, 0, G_OPTION_ARG_STRING, &connectivity_response, "the expected start of the response" },
> +		{ "connectivity-stub", 0, 0, G_OPTION_ARG_NONE, &connectivity_stub, _("Enable stub mode"), NULL },
>  		{NULL}
>  	};
>  
> @@ -455,7 +457,7 @@ main (int argc, char *argv[])
>  
>  	/* Read the config file and CLI overrides */
>  	config = nm_config_new (config_path, plugins, log_level, log_domains,
> -	                        connectivity_uri, connectivity_interval, connectivity_response, &error);
> +	                        connectivity_uri, connectivity_interval, connectivity_response, connectivity_stub, &error);
>  	if (config == NULL) {
>  		fprintf (stderr, _("Failed to read configuration: (%d) %s\n"),
>  		         error ? error->code : -1,
> @@ -593,6 +595,7 @@ main (int argc, char *argv[])
>  	                          nm_config_get_connectivity_uri (config),
>  	                          nm_config_get_connectivity_interval (config),
>  	                          nm_config_get_connectivity_response (config),
> +	                          nm_config_get_connectivity_stub (config),
>  	                          &error);
>  	if (manager == NULL) {
>  		nm_log_err (LOGD_CORE, "failed to initialize the network manager: %s",
> diff --git a/src/nm-config.c b/src/nm-config.c
> index f64b8bd..7476fca 100644
> --- a/src/nm-config.c
> +++ b/src/nm-config.c
> @@ -37,6 +37,7 @@ struct NMConfig {
>  	char *connectivity_uri;
>  	guint connectivity_interval;
>  	char *connectivity_response;
> +	gboolean connectivity_stub;
>  };
>  
>  /************************************************************************/
> @@ -124,6 +125,13 @@ nm_config_get_connectivity_response (NMConfig *config)
>  	return config->connectivity_response;
>  }
>  
> +const gboolean
> +nm_config_get_connectivity_stub (NMConfig *config)
> +{
> +	g_return_val_if_fail (config != NULL, -1);
> +
> +	return config->connectivity_stub;
> +}
>  
>  /************************************************************************/
>  
> @@ -136,6 +144,7 @@ fill_from_file (NMConfig *config,
>                  const char *cli_connectivity_uri,
>                  const gint cli_connectivity_interval,
>                  const char *cli_connectivity_response,
> +				const gboolean cli_connectivity_stub,
>                  GError **error)
>  {
>  	GKeyFile *kf;
> @@ -191,6 +200,11 @@ fill_from_file (NMConfig *config,
>  		else
>  			config->connectivity_response = g_key_file_get_value (kf, "connectivity", "response", NULL);
>  
> +		if (cli_connectivity_stub)
> +			config->connectivity_stub = cli_connectivity_stub;
> +		else
> +			config->connectivity_stub = g_key_file_get_boolean (kf, "connectivity", "stub", NULL);
> +
>  		success = TRUE;
>  	}
>  
> @@ -206,6 +220,7 @@ nm_config_new (const char *cli_config_path,
>                 const char *cli_connectivity_uri,
>                 const gint cli_connectivity_interval,
>                 const char *cli_connectivity_response,
> +			   const gboolean cli_connectivity_stub,
>                 GError **error)
>  {
>  	NMConfig *config;
> @@ -216,7 +231,7 @@ nm_config_new (const char *cli_config_path,
>  	if (cli_config_path) {
>  		/* Bad user-specific config file path is a hard error */
>  		if (!fill_from_file (config, cli_config_path, cli_plugins, cli_log_level, cli_log_domains,
> -		                     cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
> +		                     cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response, cli_connectivity_stub,
>  		                     error)) {
>  			nm_config_free (config);
>  			return NULL;
> @@ -233,7 +248,7 @@ nm_config_new (const char *cli_config_path,
>  
>  	/* Try deprecated nm-system-settings.conf first */
>  	if (fill_from_file (config, NM_OLD_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains,
> -	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
> +	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response, cli_connectivity_stub,
>  	                    &local))
>  		return config;
>  
> @@ -247,7 +262,7 @@ nm_config_new (const char *cli_config_path,
>  
>  	/* Try the standard config file location next */
>  	if (fill_from_file (config, NM_DEFAULT_SYSTEM_CONF_FILE, cli_plugins, cli_log_level, cli_log_domains,
> -	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response,
> +	                    cli_connectivity_uri, cli_connectivity_interval, cli_connectivity_response, cli_connectivity_stub,
>  	                    &local))
>  		return config;
>  
> diff --git a/src/nm-config.h b/src/nm-config.h
> index 6c4206c..068af52 100644
> --- a/src/nm-config.h
> +++ b/src/nm-config.h
> @@ -41,6 +41,7 @@ NMConfig *nm_config_new (const char *cli_config_path,
>                           const char *cli_connectivity_check_uri,
>                           const gint connectivity_check_interval,
>                           const char *cli_connectivity_check_response,
> +						 const gboolean cli_connectivity_stub,
>                           GError **error);
>  
>  const char *nm_config_get_path (NMConfig *config);
> @@ -52,6 +53,7 @@ const char *nm_config_get_log_domains (NMConfig *config);
>  const char *nm_config_get_connectivity_uri (NMConfig *config);
>  const guint nm_config_get_connectivity_interval (NMConfig *config);
>  const char *nm_config_get_connectivity_response (NMConfig *config);
> +const gboolean nm_config_get_connectivity_stub (NMConfig *config);
>  
>  void nm_config_free (NMConfig *config);
>  
> diff --git a/src/nm-manager.c b/src/nm-manager.c
> index f2816cd..af097e5 100644
> --- a/src/nm-manager.c
> +++ b/src/nm-manager.c
> @@ -215,6 +215,7 @@ typedef struct {
>  	char *hostname;
>  
>  	RadioState radio_states[RFKILL_TYPE_MAX];
> +	gboolean stub;
>  	gboolean sleeping;
>  	gboolean net_enabled;
>  
> @@ -343,6 +344,16 @@ nm_manager_get_device_by_master (NMManager *manager, const char *master, const c
>  }
>  
>  static gboolean
> +manager_stub (NMManager *self)
> +{
> +	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
> +
> +	if (priv->stub)
> +		return TRUE;
> +	return FALSE;
> +}
> +
> +static gboolean
>  manager_sleeping (NMManager *self)
>  {
>  	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
> @@ -433,6 +444,10 @@ nm_manager_update_state (NMManager *manager)
>  
>  	if (manager_sleeping (manager))
>  		new_state = NM_STATE_ASLEEP;
> +	else if (manager_stub (manager)) {
> +		nm_log_info (LOGD_CORE, "stub mode enabled, forcing state to connected.");
> +		new_state = NM_STATE_CONNECTED_GLOBAL;
> +	}
>  	else {
>  		for (iter = priv->devices; iter; iter = iter->next) {
>  			NMDevice *dev = NM_DEVICE (iter->data);
> @@ -3862,6 +3877,7 @@ nm_manager_new (NMSettings *settings,
>                  const gchar *connectivity_uri,
>                  gint connectivity_interval,
>                  const gchar *connectivity_response,
> +				gboolean connectivity_stub,
>                  GError **error)
>  {
>  	NMManagerPrivate *priv;
> @@ -3884,6 +3900,8 @@ nm_manager_new (NMSettings *settings,
>  	                  G_CALLBACK (connectivity_changed), singleton);
>  #endif
>  
> +	priv->stub = connectivity_stub;
> +
>  	bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
>  	g_assert (bus);
>  	dbus_connection = dbus_g_connection_get_connection (bus);
> diff --git a/src/nm-manager.h b/src/nm-manager.h
> index 58ba460..6bcbc85 100644
> --- a/src/nm-manager.h
> +++ b/src/nm-manager.h
> @@ -89,6 +89,7 @@ NMManager *nm_manager_new (NMSettings *settings,
>                             const gchar *connectivity_uri,
>                             gint connectivity_interval,
>                             const gchar *connectivity_response,
> +						   gboolean connectivity_stub,
>                             GError **error);
>  
>  NMManager *nm_manager_get (void);
> 
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> https://mail.gnome.org/mailman/listinfo/networkmanager-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]