diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-01-04 18:38:28 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-01-11 16:05:20 +0100 |
commit | 3392079e4b54dca7830050ee852df70ad66036aa (patch) | |
tree | 1b990d06127700d2fe69e890a7ad8bf785762fd6 /src/shared/generator.c | |
parent | generator: optionally return resulting unit file path in generator_open_unit_... (diff) | |
download | systemd-3392079e4b54dca7830050ee852df70ad66036aa.tar.xz systemd-3392079e4b54dca7830050ee852df70ad66036aa.zip |
generator: teach generator_add_symlink_full() to optionally make alias symlinks rather than just .wants/ style symlinks
Diffstat (limited to 'src/shared/generator.c')
-rw-r--r-- | src/shared/generator.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/shared/generator.c b/src/shared/generator.c index d183eb9654..b96715c59c 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -80,7 +80,6 @@ int generator_open_unit_file_full( return 0; } - int generator_add_symlink_full( const char *dir, const char *dst, @@ -93,11 +92,13 @@ int generator_add_symlink_full( assert(dir); assert(dst); - assert(dep_type); assert(src); - /* Adds a symlink from <dst>.<dep_type>/ to <src> (if src is absolute) or ../<src> (otherwise). If - * <instance> is specified, then <src> must be a template unit name, and we'll instantiate it. */ + /* If 'dep_type' is specified adds a symlink from <dst>.<dep_type>/ to <src> (if src is absolute) or ../<src> (otherwise). + * + * If 'dep_type' is NULL, it will create a symlink to <src> (i.e. create an alias. + * + * If <instance> is specified, then <src> must be a template unit name, and we'll instantiate it. */ r = path_extract_directory(src, &dn); if (r < 0 && r != -EDESTADDRREQ) /* EDESTADDRREQ → just a file name was passed */ @@ -115,11 +116,19 @@ int generator_add_symlink_full( return log_error_errno(r, "Failed to instantiate '%s' for '%s': %m", fn, instance); } - from = path_join(dn ?: "..", fn); - if (!from) - return log_oom(); + if (dep_type) { /* Create a .wants/ style dep */ + from = path_join(dn ?: "..", fn); + if (!from) + return log_oom(); - to = strjoin(dir, "/", dst, ".", dep_type, "/", instantiated ?: fn); + to = strjoin(dir, "/", dst, ".", dep_type, "/", instantiated ?: fn); + } else { /* or create an alias */ + from = dn ? path_join(dn, fn) : strdup(fn); + if (!from) + return log_oom(); + + to = strjoin(dir, "/", dst); + } if (!to) return log_oom(); |