diff options
author | Rafał Miłecki <rafal@milecki.pl> | 2019-12-28 22:07:22 +0100 |
---|---|---|
committer | Rafał Miłecki <rafal@milecki.pl> | 2020-03-21 22:41:41 +0100 |
commit | 830441d790d67147dc9d9bca4a9d3d4a7228e367 (patch) | |
tree | e9576cd226df4c6053fbc1b1c31da084bd8cd9b8 | |
parent | d1f1f2b38fa1e7b594bd005e563679a40e4d7e95 (diff) | |
download | fstools-830441d790d67147dc9d9bca4a9d3d4a7228e367.tar.gz |
blockd: remove symlink linkpath file if it's a dir or link
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 <rafal@milecki.pl>
-rw-r--r-- | blockd.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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 |