mount: check if block was mounted before cleaning it up
[project/mountd.git] / mount.c
diff --git a/mount.c b/mount.c
index 803acc1..db77f10 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -292,8 +292,10 @@ int mount_new(char *path, char *dev)
        pid = waitpid(pid, &ret, 0);
        ret = WEXITSTATUS(ret);
        log_printf("----------> mount ret = %d\n", ret);
-       if(ret && (ret != 0xff))
+       if (ret && ret != 0xff) {
+               rmdir(tmp);
                return -1;
+       }
        if(mount_wait_for_disc(mount->dev) == 0)
        {
                mount->mounted = 1;
@@ -747,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");