mount: check if block was mounted before cleaning it up
authorRafał Miłecki <rafal@milecki.pl>
Wed, 3 Jan 2018 10:31:23 +0000 (11:31 +0100)
committerJohn Crispin <john@phrozen.org>
Sun, 7 Jan 2018 11:49:37 +0000 (12:49 +0100)
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 <rafal@milecki.pl>
mount.c

diff --git a/mount.c b/mount.c
index a88ca6d469ac79661f6927e10fc73e0a0155f771..db77f10266fdd28a70b576b5d0dc5583e5a58046 100644 (file)
--- 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);
                        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");
                        free(q);
                        mount_dump_uci_state();
                        system_printf("/etc/fonstated/ReloadSamba");