From 830441d790d67147dc9d9bca4a9d3d4a7228e367 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Sat, 28 Dec 2019 22:07:22 +0100 Subject: [PATCH] blockd: remove symlink linkpath file if it's a dir or link MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Files like that can remain from using non-autofs mounting and can cause mounting errors after switching to autofs: blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 Signed-off-by: Rafał Miłecki --- blockd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockd.c b/blockd.c index 84bea6e..6e53a13 100644 --- a/blockd.c +++ b/blockd.c @@ -131,12 +131,19 @@ device_free(struct device *device) static void device_add(struct device *device) { + struct stat st; char path[64]; if (!device->autofs) return; snprintf(path, sizeof(path), "/tmp/run/blockd/%s", device->name); + if (!lstat(device->target, &st)) { + if (S_ISLNK(st.st_mode)) + unlink(device->target); + else if (S_ISDIR(st.st_mode)) + rmdir(device->target); + } if (symlink(path, device->target)) ULOG_ERR("failed to symlink %s->%s (%d) - %m\n", device->target, path, errno); else -- 2.30.2