block: simplify code picking mount target directory
[project/fstools.git] / block.c
diff --git a/block.c b/block.c
index d87251ddfa46e74fb7ad60aed3d8a49569f60acc..0671aca6d0f8231ba9f790859b513ffd75735929 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1021,10 +1021,16 @@ static int mount_device(struct probe_info *pr, int type)
        if (m && m->extroot)
                return -1;
 
+       if (type == TYPE_HOTPLUG)
+               blockd_notify(device, m, pr);
+
        if (m) {
+               char _target[32];
+               char *target;
+               int err = 0;
+
                switch (type) {
                case TYPE_HOTPLUG:
-                       blockd_notify(device, m, pr);
                        if (m->autofs)
                                return 0;
                        if (!auto_mount)
@@ -1039,20 +1045,13 @@ static int mount_device(struct probe_info *pr, int type)
                                return -1;
                        break;
                }
-       } else if (type == TYPE_HOTPLUG) {
-               blockd_notify(device, NULL, pr);
-       }
-
-       if (m) {
-               char *target = m->target;
-               char _target[32];
-               int err = 0;
 
                if (m->autofs) {
                        snprintf(_target, sizeof(_target), "/tmp/run/blockd/%s", device);
                        target = _target;
-               }
-               if (!target) {
+               } else if (m->target) {
+                       target = m->target;
+               } else {
                        snprintf(_target, sizeof(_target), "/mnt/%s", device);
                        target = _target;
                }