From b4594af55e0665917c48f0dd3cd56b49f2ea1f78 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Feb 2017 20:42:28 +0100 Subject: keyfile: updated connection when writing keyfile Writing a connection to keyfile and read it back should result in the identical setting. That is, a full round-trip would not alter any information. That is however particularly not true for certificate properties, where the keyfile writes blobs to file and coerces paths. Thus, whenver writing a keyfile we must read back what we just wrote and use that instead. --- src/settings/plugins/keyfile/nms-keyfile-connection.c | 18 ++++++++++++++++-- src/settings/plugins/keyfile/nms-keyfile-plugin.c | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/settings/plugins/keyfile/nms-keyfile-connection.c b/src/settings/plugins/keyfile/nms-keyfile-connection.c index ca98b5677..bd07d263c 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-connection.c +++ b/src/settings/plugins/keyfile/nms-keyfile-connection.c @@ -58,14 +58,16 @@ commit_changes (NMSettingsConnection *connection, { char *path = NULL; GError *error = NULL; + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; if (!nms_keyfile_writer_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, - NULL, - NULL, + &reread, + &reread_same, &error)) { callback (connection, error, user_data); g_clear_error (&error); @@ -91,6 +93,18 @@ commit_changes (NMSettingsConnection *connection, 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)); + } + } + g_free (path); NM_SETTINGS_CONNECTION_CLASS (nms_keyfile_connection_parent_class)->commit_changes (connection, diff --git a/src/settings/plugins/keyfile/nms-keyfile-plugin.c b/src/settings/plugins/keyfile/nms-keyfile-plugin.c index 0b084d6e5..d76b64c72 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-plugin.c +++ b/src/settings/plugins/keyfile/nms-keyfile-plugin.c @@ -530,18 +530,19 @@ add_connection (NMSettingsPlugin *config, { NMSKeyfilePlugin *self = NMS_KEYFILE_PLUGIN (config); gs_free char *path = NULL; + gs_unref_object NMConnection *reread = NULL; if (save_to_disk) { if (!nms_keyfile_writer_connection (connection, NULL, FALSE, &path, - NULL, + &reread, NULL, error)) return NULL; } - return NM_SETTINGS_CONNECTION (update_connection (self, connection, path, NULL, FALSE, NULL, error)); + return NM_SETTINGS_CONNECTION (update_connection (self, reread ?: connection, path, NULL, FALSE, NULL, error)); } static GSList * -- cgit v1.2.3