summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-02-28 20:42:28 +0100
committerThomas Haller <thaller@redhat.com>2017-03-02 12:14:29 +0100
commitb4594af55e0665917c48f0dd3cd56b49f2ea1f78 (patch)
tree4332795cb0c00e732d94f8fb4ba4c5455ddccf7e
parente636d28116fb09c8afb31fb5c1c322266104c0e4 (diff)
downloadNetworkManager-b4594af55e0665917c48f0dd3cd56b49f2ea1f78.tar.gz
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.
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-connection.c18
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-plugin.c5
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 ca98b5677a..bd07d263c1 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 0b084d6e55..d76b64c726 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 *