mount: call hotplug mount scripts only on success
[project/mountd.git] / mount.c
diff --git a/mount.c b/mount.c
index a7f1862..803acc1 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -139,8 +139,7 @@ static void mount_add_list(char *name, char *dev, char *serial,
 {
        struct mount *mount;
        char tmp[64], tmp2[64];
-       if(fs <= MBR || fs > LASTFS)
-               return;
+
        mount  = malloc(sizeof(struct mount));
        INIT_LIST_HEAD(&mount->list);
        strncpy(mount->vendor, vendor, 64);
@@ -155,14 +154,14 @@ static void mount_add_list(char *name, char *dev, char *serial,
        mount->mounted = 0;
        mount->fs = fs;
        list_add(&mount->list, &mounts);
-       if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= LASTFS))
+       if (!mount->ignore)
        {
                log_printf("new mount : %s -> %s (%s)\n", name, dev, fs_names[mount->fs]);
                snprintf(tmp, 64, "%s%s", uci_path, name);
                snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev);
                symlink(tmp2, tmp);
-               mount_new("/tmp/run/mountd/", dev);
-               system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);
+               if (!mount_new("/tmp/run/mountd/", dev))
+                       system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call mount", dev, name);
        }
 }
 
@@ -174,7 +173,6 @@ static int mount_check_disc(char *disc)
        if(!fp)
        {
                log_printf("error reading /proc/mounts");
-               fclose(fp);
                return avail;
        }
        while((fgets(tmp, 256, fp) != NULL) && (avail == -1))
@@ -452,6 +450,7 @@ static void mount_dev_add(char *dev)
                char sector_size[64];
                FILE *fp;
                int offset = 3;
+               int fs;
 
                strcpy(name, dev);
                if (!strncmp(name, "mmcblk", 6))
@@ -557,7 +556,11 @@ static void mount_dev_add(char *dev)
                        fclose(fp);
                }
                snprintf(tmp, 64, "/dev/%s", dev);
-               mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, detect_fs(tmp));
+               fs = detect_fs(tmp);
+               if (fs <= MBR || fs > LASTFS) {
+                       ignore = 1;
+               }
+               mount_add_list(node, dev, s, vendor, model, rev, ignore, size, sector_size, fs);
                mount_dump_uci_state();
        }
 }
@@ -615,7 +618,6 @@ static void mount_check_mount_list(void)
        if(!fp)
        {
                log_printf("error reading /proc/mounts");
-               fclose(fp);
                return;
        }
        mounted_count = 0;