about summary refs log tree commit diff
path: root/src/settings
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-05-11 17:08:25 +0200
committerMichael Biebl <biebl@debian.org>2016-05-11 17:08:25 +0200
commit73e152af6e3fb4f5848bfb8394484026ff119003 (patch)
treed5a8b37778d3a95c51511451b38b6a329b94cb41 /src/settings
parent78c3b8801ecf4975e5da1af3b10ae20dd2d876de (diff)
Imported Upstream version 1.2.2 upstream/1.2.2
Diffstat (limited to 'src/settings')
-rw-r--r--src/settings/nm-settings.c84
-rw-r--r--src/settings/plugins/ifnet/connection_parser.c11
-rw-r--r--src/settings/plugins/ifupdown/interface_parser.c16
3 files changed, 74 insertions, 37 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 4ad395a1..65148994 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -112,6 +112,10 @@ EXPORT(nm_settings_connection_replace_and_commit)
 
 #define PLUGIN_MODULE_PATH      "plugin-module-path"
 
+#if (defined(HOSTNAME_PERSIST_SUSE) + defined(HOSTNAME_PERSIST_SLACKWARE) + defined(HOSTNAME_PERSIST_GENTOO)) > 1
+#error "Can only define one of HOSTNAME_PERSIST_*"
+#endif
+
 #if defined(HOSTNAME_PERSIST_SUSE)
 #define HOSTNAME_FILE           HOSTNAME_FILE_UCASE_HOSTNAME
 #elif defined(HOSTNAME_PERSIST_SLACKWARE)
@@ -258,6 +262,7 @@ load_connections (NMSettings *self)
 	}
 
 	priv->connections_loaded = TRUE;
+	g_object_notify (G_OBJECT (self), NM_SETTINGS_CONNECTIONS);
 
 	unmanaged_specs_changed (NULL, self);
 	unrecognized_specs_changed (NULL, self);
@@ -480,27 +485,58 @@ get_plugin (NMSettings *self, guint32 capability)
 static gchar *
 read_hostname_gentoo (const char *path)
 {
-	gchar *contents = NULL, *result = NULL, *tmp;
-	gchar **all_lines = NULL;
-	guint line_num, i;
+	gs_free char *contents = NULL;
+	gs_strfreev char **all_lines = NULL;
+	const char *tmp;
+	guint i;
 
 	if (!g_file_get_contents (path, &contents, NULL, NULL))
 		return NULL;
+
 	all_lines = g_strsplit (contents, "\n", 0);
-	line_num = g_strv_length (all_lines);
-	for (i = 0; i < line_num; i++) {
+	for (i = 0; all_lines[i]; i++) {
 		g_strstrip (all_lines[i]);
 		if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
 			continue;
 		if (g_str_has_prefix (all_lines[i], "hostname=")) {
 			tmp = &all_lines[i][NM_STRLEN ("hostname=")];
-			result = g_shell_unquote (tmp, NULL);
-			break;
+			return g_shell_unquote (tmp, NULL);
 		}
 	}
-	g_strfreev (all_lines);
-	g_free (contents);
-	return result;
+	return NULL;
+}
+#endif
+
+#if defined(HOSTNAME_PERSIST_SLACKWARE)
+static gchar *
+read_hostname_slackware (const char *path)
+{
+	gs_free char *contents = NULL;
+	gs_strfreev char **all_lines = NULL;
+	char *tmp;
+	guint i, j = 0;
+
+	if (!g_file_get_contents (path, &contents, NULL, NULL))
+		return NULL;
+
+	all_lines = g_strsplit (contents, "\n", 0);
+	for (i = 0; all_lines[i]; i++) {
+		g_strstrip (all_lines[i]);
+		if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
+			continue;
+		tmp = &all_lines[i][0];
+		/* We only want up to the first '.' -- the rest of the */
+		/* fqdn is defined in /etc/hosts */
+		while (tmp[j] != '\0') {
+			if (tmp[j] == '.') {
+				tmp[j] = '\0';
+				break;
+			}
+			j++;
+		}
+		return g_shell_unquote (tmp, NULL);
+	}
+	return NULL;
 }
 #endif
 
@@ -547,18 +583,19 @@ nm_settings_get_hostname (NMSettings *self)
 		goto out;
 	}
 
-#if defined(HOSTNAME_PERSIST_GENTOO)
-	hostname = read_hostname_gentoo (priv->hostname.file);
-#else
-
 #if defined(HOSTNAME_PERSIST_SUSE)
 	if (priv->hostname.dhcp_monitor_id && hostname_is_dynamic ())
 		return NULL;
 #endif
+
+#if defined(HOSTNAME_PERSIST_GENTOO)
+	hostname = read_hostname_gentoo (priv->hostname.file);
+#elif defined(HOSTNAME_PERSIST_SLACKWARE)
+	hostname = read_hostname_slackware (priv->hostname.file);
+#else
 	if (g_file_get_contents (priv->hostname.file, &hostname, NULL, NULL))
 		g_strchomp (hostname);
-
-#endif /* HOSTNAME_PERSIST_GENTOO */
+#endif
 
 out:
 	if (hostname && !hostname[0]) {
@@ -806,18 +843,19 @@ load_plugin:
 				break;
 			}
 
+			/* after accessing the plugin we cannot unload it anymore, because the glib
+			 * types cannot be properly unregistered. */
+			g_module_make_resident (plugin);
+
 			obj = (*factory_func) ();
 			if (!obj || !NM_IS_SETTINGS_PLUGIN (obj)) {
 				g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
 				             "Plugin '%s' returned invalid system config object.",
 				             pname);
 				success = FALSE;
-				g_module_close (plugin);
 				break;
 			}
 
-			g_module_make_resident (plugin);
-			g_object_weak_ref (obj, (GWeakNotify) g_module_close, plugin);
 			g_object_set_data_full (obj, PLUGIN_MODULE_PATH, path, g_free);
 			path = NULL;
 			if (add_plugin (self, NM_SETTINGS_PLUGIN (obj)))
@@ -1960,9 +1998,11 @@ device_realized (NMDevice *device, GParamSpec *pspec, NMSettings *self)
 	g_object_unref (connection);
 
 	if (!added) {
-		_LOGW ("(%s) couldn't create default wired connection: %s",
-		       nm_device_get_iface (device),
-		       error->message);
+		if (!g_error_matches (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_UUID_EXISTS)) {
+			_LOGW ("(%s) couldn't create default wired connection: %s",
+			       nm_device_get_iface (device),
+			       error->message);
+		}
 		g_clear_error (&error);
 		return;
 	}
diff --git a/src/settings/plugins/ifnet/connection_parser.c b/src/settings/plugins/ifnet/connection_parser.c
index d9ff97dc..80b82535 100644
--- a/src/settings/plugins/ifnet/connection_parser.c
+++ b/src/settings/plugins/ifnet/connection_parser.c
@@ -1541,15 +1541,12 @@ make_wireless_security_setting (const char *conn_name,
 		if (wsec == NULL)
 			goto error;
 	}
-
-	if (!wsec) {
-		g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
-			     "Can't handle security information for ssid: %s",
-			     conn_name);
-	}
-
 	return wsec;
+
 error:
+	g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
+		     "Can't handle security information for ssid: %s",
+		     conn_name);
 	return NULL;
 }
 
diff --git a/src/settings/plugins/ifupdown/interface_parser.c b/src/settings/plugins/ifupdown/interface_parser.c
index d342501b..7ad902d4 100644
--- a/src/settings/plugins/ifupdown/interface_parser.c
+++ b/src/settings/plugins/ifupdown/interface_parser.c
@@ -39,7 +39,7 @@ if_data* last_data;
 
 void add_block(const char *type, const char* name)
 {
-	if_block *ret = (if_block*)calloc(1,sizeof(struct _if_block));
+	if_block *ret = g_slice_new0 (struct _if_block);
 	ret->name = g_strdup(name);
 	ret->type = g_strdup(type);
 	if (first == NULL)
@@ -61,7 +61,7 @@ void add_data(const char *key,const char *data)
 	if (first == NULL)
 		return;
 
-	ret = (if_data*) calloc(1,sizeof(struct _if_data));
+	ret = g_slice_new0 (struct _if_data);
 	ret->key = g_strdup(key);
 
 	/* Normalize keys. Convert '_' to '-', as ifupdown accepts both variants.
@@ -298,9 +298,9 @@ void _destroy_data(if_data *ifd)
 	if (ifd == NULL)
 		return;
 	_destroy_data(ifd->next);
-	free(ifd->key);
-	free(ifd->data);
-	free(ifd);
+	g_free(ifd->key);
+	g_free(ifd->data);
+	g_slice_free(struct _if_data, ifd);
 	return;
 }
 
@@ -310,9 +310,9 @@ void _destroy_block(if_block* ifb)
 		return;
 	_destroy_block(ifb->next);
 	_destroy_data(ifb->info);
-	free(ifb->name);
-	free(ifb->type);
-	free(ifb);
+	g_free(ifb->name);
+	g_free(ifb->type);
+	g_slice_free(struct _if_block, ifb);
 	return;
 }