summary refs log tree commit diff
path: root/src/settings/plugins/keyfile
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2017-11-07 00:14:39 +0100
committerMichael Biebl <biebl@debian.org>2017-11-07 00:14:39 +0100
commit90e8691111889a7b5f3c812f5a41f15a8a058913 (patch)
treef101a879eca27c34a9bfa5f3da52266b22539a36 /src/settings/plugins/keyfile
parentbdb6eeb0670658255c2a4c3c501c0a27fa8cfe55 (diff)
New upstream version 1.9.90 upstream/1.9.90
Diffstat (limited to 'src/settings/plugins/keyfile')
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-connection.c74
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-plugin.c4
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-writer.c3
-rw-r--r--src/settings/plugins/keyfile/tests/test-keyfile.c6
4 files changed, 38 insertions, 49 deletions
diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c
index bd07d263..300aa9f7 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-connection.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c
@@ -50,29 +50,30 @@ G_DEFINE_TYPE (NMSKeyfileConnection, nms_keyfile_connection, NM_TYPE_SETTINGS_CO
 
 /*****************************************************************************/
 
-static void
+static gboolean
 commit_changes (NMSettingsConnection *connection,
+                NMConnection *new_connection,
                 NMSettingsConnectionCommitReason commit_reason,
-                NMSettingsConnectionCommitFunc callback,
-                gpointer user_data)
+                NMConnection **out_reread_connection,
+                char **out_logmsg_change,
+                GError **error)
 {
-	char *path = NULL;
-	GError *error = NULL;
+	gs_free char *path = NULL;
 	gs_unref_object NMConnection *reread = NULL;
 	gboolean reread_same = FALSE;
 
-	if (!nms_keyfile_writer_connection (NM_CONNECTION (connection),
+	nm_assert (out_reread_connection && !*out_reread_connection);
+	nm_assert (!out_logmsg_change || !*out_logmsg_change);
+
+	if (!nms_keyfile_writer_connection (new_connection ?: NM_CONNECTION (connection),
 	                                    nm_settings_connection_get_filename (connection),
 	                                    NM_FLAGS_ALL (commit_reason,   NM_SETTINGS_CONNECTION_COMMIT_REASON_USER_ACTION
 	                                                                 | NM_SETTINGS_CONNECTION_COMMIT_REASON_ID_CHANGED),
 	                                    &path,
 	                                    &reread,
 	                                    &reread_same,
-	                                    &error)) {
-		callback (connection, error, user_data);
-		g_clear_error (&error);
-		return;
-	}
+	                                    error))
+		return FALSE;
 
 	/* Update the filename if it changed */
 	if (   path
@@ -81,52 +82,37 @@ commit_changes (NMSettingsConnection *connection,
 
 		nm_settings_connection_set_filename (connection, path);
 		if (old_path) {
-			nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"",
-			             NMS_KEYFILE_CONNECTION_LOG_ARG (connection),
-			             old_path);
+			NM_SET_OUT (out_logmsg_change,
+			            g_strdup_printf ("keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and rename from \"%s\"",
+			                             NMS_KEYFILE_CONNECTION_LOG_ARG (connection),
+			                             old_path));
 		} else {
-			nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and persist connection",
-			             NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
+			NM_SET_OUT (out_logmsg_change,
+			            g_strdup_printf ("keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" and persist connection",
+			                             NMS_KEYFILE_CONNECTION_LOG_ARG (connection)));
 		}
 	} else {
-		nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT,
-		             NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
-	}
-
-	if (reread && !reread_same) {
-		gs_free_error GError *local = NULL;
-
-		if (!nm_settings_connection_replace_settings (connection, reread, FALSE, "update-during-write", &local)) {
-			nm_log_warn (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" after persisting connection failed: %s",
-			             NMS_KEYFILE_CONNECTION_LOG_ARG (connection), local->message);
-		} else {
-			nm_log_info (LOGD_SETTINGS, "keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT" after persisting connection",
-			             NMS_KEYFILE_CONNECTION_LOG_ARG (connection));
-		}
+		NM_SET_OUT (out_logmsg_change,
+		            g_strdup_printf ("keyfile: update "NMS_KEYFILE_CONNECTION_LOG_FMT,
+		                             NMS_KEYFILE_CONNECTION_LOG_ARG (connection)));
 	}
 
-	g_free (path);
+	if (reread && !reread_same)
+		*out_reread_connection = g_steal_pointer (&reread);
 
-	NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->commit_changes (connection,
-	                                                                                    commit_reason,
-	                                                                                    callback,
-	                                                                                    user_data);
+	return TRUE;
 }
 
-static void
-do_delete (NMSettingsConnection *connection,
-           NMSettingsConnectionDeleteFunc callback,
-           gpointer user_data)
+static gboolean
+delete (NMSettingsConnection *connection,
+        GError **error)
 {
 	const char *path;
 
 	path = nm_settings_connection_get_filename (connection);
 	if (path)
 		g_unlink (path);
-
-	NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->delete (connection,
-	                                                                            callback,
-	                                                                            user_data);
+	return TRUE;
 }
 
 /*****************************************************************************/
@@ -192,5 +178,5 @@ nms_keyfile_connection_class_init (NMSKeyfileConnectionClass *keyfile_connection
 	NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (keyfile_connection_class);
 
 	settings_class->commit_changes = commit_changes;
-	settings_class->delete = do_delete;
+	settings_class->delete = delete;
 }
diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
index 4af80142..ee4db320 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c
@@ -378,7 +378,7 @@ _paths_from_connections (GHashTable *connections)
 {
 	GHashTableIter iter;
 	NMSKeyfileConnection *connection;
-	GHashTable *paths = g_hash_table_new (g_str_hash, g_str_equal);
+	GHashTable *paths = g_hash_table_new (nm_str_hash, g_str_equal);
 
 	g_hash_table_iter_init (&iter, connections);
 	while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &connection)) {
@@ -588,7 +588,7 @@ nms_keyfile_plugin_init (NMSKeyfilePlugin *plugin)
 	NMSKeyfilePluginPrivate *priv = NMS_KEYFILE_PLUGIN_GET_PRIVATE (plugin);
 
 	priv->config = g_object_ref (nm_config_get ());
-	priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+	priv->connections = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_object_unref);
 }
 
 static void
diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
index 92ed2849..270a217e 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
@@ -213,6 +213,9 @@ _internal_write_connection (NMConnection *connection,
 	if (!data)
 		return FALSE;
 
+	if (!g_file_test (keyfile_dir, G_FILE_TEST_IS_DIR))
+		(void) g_mkdir_with_parents (keyfile_dir, 0755);
+
 	/* If we have existing file path, use it. Else generate one from
 	 * connection's ID.
 	 */
diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c
index d9da5317..2584a722 100644
--- a/src/settings/plugins/keyfile/tests/test-keyfile.c
+++ b/src/settings/plugins/keyfile/tests/test-keyfile.c
@@ -312,11 +312,11 @@ test_read_valid_wired_connection (void)
 	check_ip_route (s_ip4, 3, "1.1.1.3", 13, NULL, -1);
 	check_ip_route (s_ip4, 4, "1.1.1.4", 14, "2.2.2.4", -1);
 	check_ip_route (s_ip4, 5, "1.1.1.5", 15, "2.2.2.5", -1);
-	check_ip_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", -1);
+	check_ip_route (s_ip4, 6, "1.1.1.6", 16, "2.2.2.6", 0);
 	check_ip_route (s_ip4, 7, "1.1.1.7", 17, NULL, -1);
 	check_ip_route (s_ip4, 8, "1.1.1.8", 18, NULL, -1);
-	check_ip_route (s_ip4, 9, "1.1.1.9", 19, NULL, -1);
-	check_ip_route (s_ip4, 10, "1.1.1.10", 20, NULL, -1);
+	check_ip_route (s_ip4, 9, "1.1.1.9", 19, NULL, 0);
+	check_ip_route (s_ip4, 10, "1.1.1.10", 20, NULL, 0);
 	check_ip_route (s_ip4, 11, "1.1.1.11", 21, NULL, 21);
 
 	/* Route attributes */