From c54e5c6e09bf8e8debea05dd0dac095624a2472b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 3 Jan 2018 11:31:23 +0100 Subject: [PATCH] mount: check if block was mounted before cleaning it up MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Calling an extra rmdir and unlink isn't a big issue but triggering hotplug.d scripts for devices that weren't mounted could be misleading for listeners. Signed-off-by: Rafał Miłecki --- mount.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mount.c b/mount.c index a88ca6d..db77f10 100644 --- a/mount.c +++ b/mount.c @@ -749,11 +749,13 @@ static void mount_enum_drives(void) p->next->prev = p->prev; p = p->next; log_printf("removing %s\n", q->dev); - snprintf(tmp, 64, "%s%s", "/tmp/run/mountd/", q->dev); - rmdir(tmp); - snprintf(tmp, 64, "%s%s", uci_path, q->name); - unlink(tmp); - system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name); + if (q->mounted) { + snprintf(tmp, 64, "%s%s", "/tmp/run/mountd/", q->dev); + rmdir(tmp); + snprintf(tmp, 64, "%s%s", uci_path, q->name); + unlink(tmp); + system_printf("ACTION=remove DEVICE=%s NAME=%s /sbin/hotplug-call mount", q->dev, q->name); + } free(q); mount_dump_uci_state(); system_printf("/etc/fonstated/ReloadSamba"); -- 2.25.1