diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-02-13 01:07:02 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-02-13 01:07:02 +0100 |
commit | 036643a247c659db8e1b3df1778d51553a816ec9 (patch) | |
tree | 1ffe6bdfec708fec46adb58c531bb2455f399cee /load-fragment.c | |
parent | 65d2ebdc3408c81a947de8712b37b9398d955465 (diff) |
config: implement search path logic
Diffstat (limited to 'load-fragment.c')
-rw-r--r-- | load-fragment.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/load-fragment.c b/load-fragment.c index 95e6cc3f88..64e66f314e 100644 --- a/load-fragment.c +++ b/load-fragment.c @@ -1128,7 +1128,7 @@ static int load_from_path(Unit *u, const char *path) { int r; Set *symlink_names; FILE *f; - char *filename, *id; + char *filename = NULL, *id; sections[0] = "Meta"; sections[1] = section_table[u->meta.type]; @@ -1137,18 +1137,56 @@ static int load_from_path(Unit *u, const char *path) { if (!(symlink_names = set_new(string_hash_func, string_compare_func))) return -ENOMEM; - /* Instead of opening the path right away, we manually - * follow all symlinks and add their name to our unit - * name set while doing so */ - if (!(filename = path_make_absolute(path, unit_path()))) { - r = -ENOMEM; - goto finish; - } + if (path_is_absolute(path)) { + + if (!(filename = strdup(path))) { + r = -ENOMEM; + goto finish; + } + + if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) { + free(filename); + filename = NULL; - if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) { - if (r == -ENOENT) - r = 0; /* returning 0 means: no suitable config file found */ + if (r != -ENOENT) + goto finish; + } + + } else { + char **p; + + STRV_FOREACH(p, u->meta.manager->unit_path) { + + /* Instead of opening the path right away, we manually + * follow all symlinks and add their name to our unit + * name set while doing so */ + if (!(filename = path_make_absolute(path, *p))) { + r = -ENOMEM; + goto finish; + } + + if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) { + char *sn; + + free(filename); + filename = NULL; + + if (r != -ENOENT) + goto finish; + + /* Empty the symlink names for the next run */ + while ((sn = set_steal_first(symlink_names))) + free(sn); + + continue; + } + + break; + } + } + if (!filename) { + r = 0; /* returning 0 means: no suitable config file found */ goto finish; } |