Re: [PATCH] Easy patch (help out!): preserve wireless-enabled and networking-enabled



On 10/27/2009 07:58 AM, Jirka Klimes wrote:
On Friday 23 October 2009 19:19:14 Dan Williams wrote:
  
Anyone want to do a really simple patch?  It would close some bugs and
help out a lot:

    
Hello Dan,

I've done the patch. Please, review it.
  

Jirka --

You beat me to the punch...  I finished up my version last night, but hadn't tested it yet.

You version is actually a little bit cleaner, as I hadn't created a new struct for the config parameters.  I've attached my version ( which is actually a quilt patch for Ubuntu ) for reference.

The one thing I think you may have missed, is checking for G_KEY_FILE_ERROR_INVALID_VALUE when reading the values from the file.  Other than that, looks good to me!

Regards,
/tony





NetworkingEnabled and WirelessEnabled are read from config file. If not present, 
the values are regarded as true; if case of mangled values (or something), 
false is used.
On changing values in the applet, the keys are changed (created)
in the cofiguration file.

Jirka
  
_______________________________________________ NetworkManager-list mailing list NetworkManager-list gnome org http://mail.gnome.org/mailman/listinfo/networkmanager-list

Index: network-manager-0.8~a~git.20091013t193206.679d548/src/NetworkManager.c
===================================================================
--- network-manager-0.8~a~git.20091013t193206.679d548.orig/src/NetworkManager.c	2009-10-26 21:29:13.647651662 -0400
+++ network-manager-0.8~a~git.20091013t193206.679d548/src/NetworkManager.c	2009-10-26 21:29:13.751628571 -0400
@@ -242,7 +242,11 @@
 }
 
 static gboolean
-parse_config_file (const char *filename, char **plugins, GError **error)
+parse_config_file (const char *filename,
+				   char **plugins,
+				   gboolean *net_enabled,
+				   gboolean *wireless_enabled,
+				   GError **error)
 {
 	GKeyFile *config;
 
@@ -261,7 +265,35 @@
 	if (*error)
 		return FALSE;
 
-	g_key_file_free (config);
+	*net_enabled = g_key_file_get_boolean (config, "main", "NetEnabled", error);
+	if (*error) {
+		if (g_error_matches(*error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+			*net_enabled = TRUE;
+		else {
+			if (g_error_matches(*error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE))
+				nm_error ("Invalid value found for NetEnabled in config file: %s", filename);
+			else
+				nm_error ("Unknown error reading NetEnabled from config file: %s", filename);
+
+			return FALSE;
+		}
+	}
+
+	*wireless_enabled = g_key_file_get_boolean (config, "main", "WirelessEnabled", error);
+	if (*error) {
+		if (g_error_matches(*error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
+			*wireless_enabled = TRUE;
+		else {
+			if (g_error_matches(*error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE))
+				nm_error ("Invalid value found for WirelessEnabled in config file: %s", filename);
+			else
+				nm_error ("Unknown error reading WirelessEnabled from config file: %s", filename);
+
+			return FALSE;
+		}
+	}
+
+ 	g_key_file_free (config);
 	return TRUE;
 }
 
@@ -275,6 +307,7 @@
 	GOptionContext *opt_ctx = NULL;
 	gboolean become_daemon = FALSE;
 	gboolean g_fatal_warnings = FALSE;
+	gboolean net_enabled, wireless_enabled = TRUE;
 	char *pidfile = NULL, *user_pidfile = NULL;
 	char *config = NULL, *plugins = NULL;
 	gboolean success;
@@ -329,7 +362,7 @@
 
 	/* Parse the config file */
 	if (config) {
-		if (!parse_config_file (config, &plugins, &error)) {
+		if (!parse_config_file (config, &plugins, &net_enabled, &wireless_enabled, &error)) {
 			g_warning ("Config file %s invalid: (%d) %s.",
 			           config,
 			           error ? error->code : -1,
@@ -338,7 +371,7 @@
 		}
 	} else {
 		config = NM_DEFAULT_SYSTEM_CONF_FILE;
-		if (!parse_config_file (config, &plugins, &error)) {
+		if (!parse_config_file (config, &plugins, &net_enabled, &wireless_enabled, &error)) {
 			g_warning ("Default config file %s invalid: (%d) %s.",
 			           config,
 			           error ? error->code : -1,
@@ -415,7 +448,11 @@
 		goto done;
 	}
 
-	manager = nm_manager_get (config, plugins, &error);
+	manager = nm_manager_get (config,
+							  plugins,
+							  net_enabled,
+							  wireless_enabled,
+							  &error);
 	if (manager == NULL) {
 		nm_error ("Failed to initialize the network manager: %s",
 		          error && error->message ? error->message : "(unknown)");
Index: network-manager-0.8~a~git.20091013t193206.679d548/src/nm-device-olpc-mesh.c
===================================================================
--- network-manager-0.8~a~git.20091013t193206.679d548.orig/src/nm-device-olpc-mesh.c	2009-10-14 18:03:07.000000000 -0400
+++ network-manager-0.8~a~git.20091013t193206.679d548/src/nm-device-olpc-mesh.c	2009-10-26 21:29:13.751628571 -0400
@@ -909,7 +909,8 @@
 	if (priv->device_added_cb != 0)
 		return FALSE;
 
-	manager = nm_manager_get (NULL, NULL, NULL);
+	/* Used to get singleton, all parameters ignored... */
+	manager = nm_manager_get (NULL, NULL, FALSE, FALSE, NULL);
 
 	priv->device_added_cb = g_signal_connect (manager, "device-added",
 	                                          G_CALLBACK (device_added_cb), self);
Index: network-manager-0.8~a~git.20091013t193206.679d548/src/nm-manager.c
===================================================================
--- network-manager-0.8~a~git.20091013t193206.679d548.orig/src/nm-manager.c	2009-10-26 21:29:13.663638141 -0400
+++ network-manager-0.8~a~git.20091013t193206.679d548/src/nm-manager.c	2009-10-26 21:34:59.518629892 -0400
@@ -1109,6 +1109,9 @@
 {
 	NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
 	GSList *iter;
+	GKeyFile *config;
+	gsize len = 0;
+	char *data;
 
 	if (priv->wireless_enabled == enabled)
 		return;
@@ -1130,6 +1133,20 @@
 		if (NM_IS_DEVICE_WIFI (iter->data))
 			nm_device_wifi_set_enabled (NM_DEVICE_WIFI (iter->data), enabled);
 	}
+
+	config = g_key_file_new ();
+	if (config) {
+		/* Do I need to do this??? probably doesn't hurt... */
+		g_key_file_set_list_separator (config, ',');
+		g_key_file_load_from_file (config, priv->config_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
+		g_key_file_set_boolean(config, "main", "WirelessEnabled", enabled);
+
+		data = g_key_file_to_data (config, &len, NULL);
+		if (data) {
+			g_file_set_contents (priv->config_file, data, len, NULL);
+			g_free (data);
+		}
+	}
 }
 
 static void
@@ -2366,7 +2383,10 @@
 impl_manager_sleep (NMManager *self, gboolean sleep, GError **error)
 {
 	NMManagerPrivate *priv;
+	GKeyFile *config;
 	GSList *iter;
+	gsize len = 0;
+	char *data;
 
 	g_return_val_if_fail (NM_IS_MANAGER (self), FALSE);
 
@@ -2412,6 +2432,23 @@
 	}
 
 	nm_manager_update_state (self);
+
+	config = g_key_file_new ();
+	if (!config)
+		goto cleanup;
+
+	/* Do I need to do this??? probably doesn't hurt... */
+	g_key_file_set_list_separator (config, ',');
+	g_key_file_load_from_file (config, priv->config_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
+	g_key_file_set_boolean(config, "main", "NetEnabled", !sleep);
+
+	data = g_key_file_to_data (config, &len, NULL);
+	if (data) {
+		g_file_set_contents (priv->config_file, data, len, NULL);
+		g_free (data);
+	}
+
+ cleanup:
 	return TRUE;
 }
 
@@ -2569,7 +2606,11 @@
 }
 
 NMManager *
-nm_manager_get (const char *config_file, const char *plugins, GError **error)
+nm_manager_get (const char *config_file,
+				const char *plugins,
+				gboolean net_enabled,
+				gboolean wireless_enabled,
+				GError **error)
 {
 	static NMManager *singleton = NULL;
 	NMManagerPrivate *priv;
@@ -2586,6 +2627,9 @@
 	bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
 	g_assert (bus);
 
+	priv->sleeping = !net_enabled;
+	priv->wireless_enabled = wireless_enabled;
+
 	priv->sys_settings = nm_sysconfig_settings_new (config_file, plugins, bus, error);
 	if (!priv->sys_settings) {
 		g_object_unref (singleton);
Index: network-manager-0.8~a~git.20091013t193206.679d548/src/nm-manager.h
===================================================================
--- network-manager-0.8~a~git.20091013t193206.679d548.orig/src/nm-manager.h	2009-10-14 18:03:07.000000000 -0400
+++ network-manager-0.8~a~git.20091013t193206.679d548/src/nm-manager.h	2009-10-26 21:29:13.755651570 -0400
@@ -73,7 +73,11 @@
 
 GType nm_manager_get_type (void);
 
-NMManager *nm_manager_get (const char *config_file, const char *plugins, GError **error);
+NMManager *nm_manager_get (const char *config_file,
+						   const char *plugins,
+						   gboolean net_enabled,
+						   gboolean wireless_enabled,
+						   GError **error);
 
 void nm_manager_start (NMManager *manager);
 


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