summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-09-27 13:51:55 +0200
committerThomas Haller <thaller@redhat.com>2018-10-04 10:58:50 +0200
commit679d24ef7d8be4bbc927254f2a6d2bc1dc9fafff (patch)
treeb0402a0104e4b0e8e8a8c7c7a75e9888d06c78b1
parent8eab707481398bfb8aed5fec8e362f6365187b01 (diff)
core: add code comment to nm_utils_read_link_absolute() and minor cleanup
-rw-r--r--src/nm-core-utils.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 97866256d..99fa8c952 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -1114,13 +1114,17 @@ nm_utils_read_link_absolute (const char *link_file, GError **error)
return ln;
dirname = g_path_get_dirname (link_file);
- if (!g_path_is_absolute (link_file)) {
- gs_free char *dirname_rel = dirname;
+ if (!g_path_is_absolute (dirname)) {
gs_free char *current_dir = g_get_current_dir ();
- dirname = g_build_filename (current_dir, dirname_rel, NULL);
- }
- ln_abs = g_build_filename (dirname, ln, NULL);
+ /* @link_file argument was not an absolute path in the first place.
+ * That actually may be a bug, because the CWD is not well defined
+ * in most cases. Anyway, apparently we were able to load the file
+ * even from a relative path. So, when making the link absolute, we
+ * also need to prepend the CWD. */
+ ln_abs = g_build_filename (current_dir, dirname, ln, NULL);
+ } else
+ ln_abs = g_build_filename (dirname, ln, NULL);
g_free (dirname);
g_free (ln);
return ln_abs;