block: simplify code picking mount target directory
authorRafał Miłecki <rafal@milecki.pl>
Fri, 30 Nov 2018 13:09:22 +0000 (14:09 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 4 Dec 2018 08:15:34 +0000 (09:15 +0100)
Using a set of 3 conditional block each setting "target" variable makes
code easier to follow.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Michael Heimpold <mhei@heimpold.de>
block.c

diff --git a/block.c b/block.c
index f42d0d62b84a9e667253e374d34570f9a10e6a77..0671aca6d0f8231ba9f790859b513ffd75735929 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1025,8 +1025,8 @@ static int mount_device(struct probe_info *pr, int type)
                blockd_notify(device, m, pr);
 
        if (m) {
-               char *target = m->target;
                char _target[32];
+               char *target;
                int err = 0;
 
                switch (type) {
@@ -1049,8 +1049,9 @@ static int mount_device(struct probe_info *pr, int type)
                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;
                }