summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-01-10 17:24:18 +0100
committerThomas Haller <thaller@redhat.com>2020-01-16 12:40:01 +0100
commit4fc7c7eec01b75c37c5690e13e62c5585767a5ef (patch)
tree63b57c6510b231a5ace1ac4d6541501debd49490
parent16ba286e3002b800a6f525309c126e5e8a7cdb6e (diff)
downloadNetworkManager-4fc7c7eec01b75c37c5690e13e62c5585767a5ef.tar.gz
ifcfg-rh: avoid creaing route file twice in make_ip4_setting()
Just read the content once. It's wasteful to read the file twice while parsing. But what is worse, the file content can change any time we read it. We make decisions based on what we read, and hence we should only read the file once in the parsing process to get one consistent result.
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
index c59bdbafe6..9110d68d75 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
@@ -1620,7 +1620,6 @@ make_ip4_setting (shvarFile *ifcfg,
int i;
guint32 a;
gboolean has_key;
- shvarFile *route_ifcfg;
gboolean never_default;
gint64 i64;
int priority;
@@ -1857,32 +1856,34 @@ make_ip4_setting (shvarFile *ifcfg,
/* Static routes - route-<name> file */
route_path = utils_get_route_path (svFileGetName (ifcfg));
- if (!routes_read) {
- /* NOP */
- } else if (utils_has_route_file_new_syntax (route_path)) {
- /* Parse route file in new syntax */
- route_ifcfg = utils_get_route_ifcfg (svFileGetName (ifcfg), FALSE);
- if (route_ifcfg) {
+ if (routes_read) {
+ gs_free char *contents = NULL;
+ gsize len;
+
+ if (!g_file_get_contents (route_path, &contents, &len, NULL))
+ len = 0;
+
+ if (utils_has_route_file_new_syntax_content (contents, len)) {
+ nm_auto_shvar_file_close shvarFile *route_ifcfg = NULL;
+
+ /* Parse route file in new syntax */
+ route_ifcfg = svFile_new (route_path, -1, contents);
for (i = 0;; i++) {
- NMIPRoute *route = NULL;
+ nm_auto_unref_ip_route NMIPRoute *route = NULL;
- if (!read_one_ip4_route (route_ifcfg, i, &route, error)) {
- svCloseFile (route_ifcfg);
+ if (!read_one_ip4_route (route_ifcfg, i, &route, error))
return NULL;
- }
if (!route)
break;
if (!nm_setting_ip_config_add_route (s_ip4, route))
PARSE_WARNING ("duplicate IP4 route");
- nm_ip_route_unref (route);
}
- svCloseFile (route_ifcfg);
+ } else {
+ if (!read_route_file_parse (AF_INET, route_path, contents, len, s_ip4, error))
+ return NULL;
}
- } else {
- if (!read_route_file (AF_INET, route_path, s_ip4, error))
- return NULL;
}
/* Legacy value NM used for a while but is incorrect (rh #459370) */