chiark / gitweb /
util: introduce readlink_and_make_absolute()
[elogind.git] / src / load-fragment.c
index 5f5e37397b222c4354be13ef5eb02bc527eb0bb2..793c9525941a9c4fc307a10de93f342966e655be 100644 (file)
@@ -1160,7 +1160,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
          * reached by a symlink. The old string will be freed. */
 
         for (;;) {
-                char *target, *k, *name;
+                char *target, *name;
 
                 if (c++ >= FOLLOW_MAX)
                         return -ELOOP;
@@ -1189,17 +1189,11 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
                         return -errno;
 
                 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
-                if ((r = readlink_malloc(*filename, &target)) < 0)
+                if ((r = readlink_and_make_absolute(*filename, &target)) < 0)
                         return r;
 
-                k = file_in_same_dir(*filename, target);
-                free(target);
-
-                if (!k)
-                        return -ENOMEM;
-
                 free(*filename);
-                *filename = k;
+                *filename = target;
         }
 
         if (!(f = fdopen(fd, "r"))) {
@@ -1483,7 +1477,6 @@ static int load_from_path(Unit *u, const char *path) {
 #undef EXEC_CONTEXT_CONFIG_ITEMS
 
         const char *sections[3];
-        char *k;
         int r;
         Set *symlink_names;
         FILE *f = NULL;
@@ -1524,7 +1517,7 @@ static int load_from_path(Unit *u, const char *path) {
         } else  {
                 char **p;
 
-                STRV_FOREACH(p, u->meta.manager->unit_path) {
+                STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
 
                         /* Instead of opening the path right away, we manually
                          * follow all symlinks and add their name to our unit
@@ -1581,10 +1574,7 @@ static int load_from_path(Unit *u, const char *path) {
         r = 0;
 
 finish:
-        while ((k = set_steal_first(symlink_names)))
-                free(k);
-
-        set_free(symlink_names);
+        set_free_free(symlink_names);
         free(filename);
 
         if (f)