diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-07-09 23:59:30 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-07-13 18:56:36 -0400 |
commit | 7f0cc63771aeb792bb5fff1e22c471132ffa054b (patch) | |
tree | 4d93ab89b9be781daaa75896bd7aa311f576e0c3 /src/sysv-generator/sysv-generator.c | |
parent | 9cdcf3681c1a4139aff34541b5648234bf4aa1b1 (diff) | |
download | systemd-7f0cc63771aeb792bb5fff1e22c471132ffa054b.tar.gz systemd-7f0cc63771aeb792bb5fff1e22c471132ffa054b.tar.bz2 systemd-7f0cc63771aeb792bb5fff1e22c471132ffa054b.zip |
sysv-generator: use generator_add_symlink()
generator_add_symlink() is extended to ignore EEXIST. This should be fine
for all existing callers.
There's a small difference in behaviour when adding symlinks in sysv-generator:
the message is more generic and does not include ", ignored". But creation of
symlinks shouldn't ever fail except if things are very wrong, so in practice
this shouldn't matter.
Test needed updating: os.path.exists(os.readlink(link)) only works if the link
is absolute (or if we are in the right directory). Let's just use
os.path.exists(link), which properly tests that the symlink target exists.
Diffstat (limited to 'src/sysv-generator/sysv-generator.c')
-rw-r--r-- | src/sysv-generator/sysv-generator.c | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 9828078443..3f3237d9b3 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -28,6 +28,7 @@ #include "exit-status.h" #include "fd-util.h" #include "fileio.h" +#include "generator.h" #include "hashmap.h" #include "hexdecoct.h" #include "install.h" @@ -101,29 +102,6 @@ static void free_sysvstub_hashmapp(Hashmap **h) { hashmap_free(*h); } -static int add_symlink(const char *service, const char *where) { - const char *from, *to; - int r; - - assert(service); - assert(where); - - from = strjoina(arg_dest, "/", service); - to = strjoina(arg_dest, "/", where, ".wants/", service); - - mkdir_parents_label(to, 0755); - - r = symlink(from, to); - if (r < 0) { - if (errno == EEXIST) - return 0; - - return -errno; - } - - return 1; -} - static int add_alias(const char *service, const char *alias) { const char *link; int r; @@ -219,11 +197,8 @@ static int generate_unit_file(SysvStub *s) { if (r < 0) return log_error_errno(r, "Failed to write unit %s: %m", unit); - STRV_FOREACH(p, s->wanted_by) { - r = add_symlink(s->name, *p); - if (r < 0) - log_warning_errno(r, "Failed to create 'Wants' symlink to %s, ignoring: %m", *p); - } + STRV_FOREACH(p, s->wanted_by) + (void) generator_add_symlink(arg_dest, *p, "wants", s->name); return 1; } |