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>
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