From: Lennart Poettering Date: Wed, 27 Sep 2017 15:48:28 +0000 (+0200) Subject: socket: if RemoveOnStop= is turned on for a socket, try to unlink() pre-existing... X-Git-Tag: v235~51^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=22b20752e20ce0e637083067b450f61cf4acf691;p=thirdparty%2Fsystemd.git socket: if RemoveOnStop= is turned on for a socket, try to unlink() pre-existing symlinks Normally, Symlinks= failing is not considered fatal nor destructive. Let's slightly alter behaviour here if RemoveOnStop= is turned on. In that case the use in a way opted for destructive behaviour and we do unlink all sockets and symlinks when the socket unit goes down. And that means we might as well unlink any pre-existing if this mode is selected. Yeah, it's a bit of a stretch to do this, but @OhNoMoreGit is right: if RemoveOnStop= is on we are destructive regarding any pre-existing symlinks on stop, and it would be quite weird if we wouldn't be on start. --- diff --git a/src/core/socket.c b/src/core/socket.c index 157a6dbae74..ba70756d839 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1337,6 +1337,16 @@ static int socket_symlink(Socket *s) { (void) mkdir_parents_label(*i, s->directory_mode); r = symlink_idempotent(p, *i); + + if (r == -EEXIST && s->remove_on_stop) { + /* If there's already something where we want to create the symlink, and the destructive + * RemoveOnStop= mode is set, then we might as well try to remove what already exists and try + * again. */ + + if (unlink(*i) >= 0) + r = symlink_idempotent(p, *i); + } + if (r < 0) log_unit_warning_errno(UNIT(s), r, "Failed to create symlink %s → %s, ignoring: %m", p, *i); }