From 3c3fc089ad473b6b97cbd16140ea806095ce6b7d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 Oct 2017 12:55:31 +0200 Subject: [PATCH] settings: return re-read connection from ifcfg-rh writer As writing a connection to disk might modify it, we re-read it back and use what we actually found on disk. For example, if you have a connection with ipv6.method=ignore, ifcfg-rh writer will not persist the ipv6.route-metric. That is likely a bug in the writer. Before this patch, changing the route metric would seemingly succeed, but on the next reload from this, the changes are lost. We should fix such bugs. Regardless, it's better to pick up what we wrote to disk, instead of later. --- .../ifcfg-rh/nms-ifcfg-rh-connection.c | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 1e5b68927b..06b11d4f41 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -332,6 +332,9 @@ commit_changes (NMSettingsConnection *connection, GError **error) { const char *filename; + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = TRUE; + const char *operation_message; nm_assert (out_reread_connection && !*out_reread_connection); nm_assert (!out_logmsg_change || !*out_logmsg_change); @@ -343,28 +346,29 @@ commit_changes (NMSettingsConnection *connection, if (!writer_new_connection (new_connection ?: NM_CONNECTION (connection), IFCFG_DIR, &ifcfg_path, - NULL, - NULL, + &reread, + &reread_same, error)) return FALSE; nm_settings_connection_set_filename (connection, ifcfg_path); - NM_SET_OUT (out_logmsg_change, - g_strdup_printf ("ifcfg-rh: persist %s", - ifcfg_path)); - return TRUE; + operation_message = "persist"; + } else { + if (!writer_update_connection (new_connection ?: NM_CONNECTION (connection), + IFCFG_DIR, + filename, + &reread, + &reread_same, + error)) + return FALSE; + operation_message = "update"; } - if (!writer_update_connection (new_connection ?: NM_CONNECTION (connection), - IFCFG_DIR, - filename, - NULL, - NULL, - error)) - return FALSE; + if (reread && !reread_same) + *out_reread_connection = g_steal_pointer (&reread); NM_SET_OUT (out_logmsg_change, - g_strdup_printf ("ifcfg-rh: update %s", - filename)); + g_strdup_printf ("ifcfg-rh: %s %s", + operation_message, filename)); return TRUE; }