From: Jo-Philipp Wich Date: Fri, 21 Oct 2016 13:46:25 +0000 (+0200) Subject: block: fix error reporting X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=13345aa36e13038a02a6dccf6b5181d9961dc2e0;p=oweals%2Ffstools.git block: fix error reporting The current block code wrongly reported the return value of the mount() and umount2() syscalls, which is always -1 in case the call failed. Use errno and strerror(errno) instead to propagate the correct error code to the user. Signed-off-by: Jo-Philipp Wich --- diff --git a/block.c b/block.c index 9de8343..8de83b7 100644 --- a/block.c +++ b/block.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -804,7 +805,7 @@ static int mount_device(struct probe_info *pr, int hotplug) (m->options) ? (m->options) : ("")); if (err) ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->type, target, err, strerror(err)); + pr->dev, pr->type, target, errno, strerror(errno)); else handle_swapfiles(true); return err; @@ -823,7 +824,7 @@ static int mount_device(struct probe_info *pr, int hotplug) err = mount(pr->dev, target, pr->type, 0, ""); if (err) ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n", - pr->dev, pr->type, target, err, strerror(err)); + pr->dev, pr->type, target, errno, strerror(errno)); else handle_swapfiles(true); return err; @@ -856,7 +857,7 @@ static int umount_device(struct probe_info *pr) err = umount2(mp, MNT_DETACH); if (err) ULOG_ERR("unmounting %s (%s) failed (%d) - %s\n", - pr->dev, mp, err, strerror(err)); + pr->dev, mp, errno, strerror(errno)); else ULOG_INFO("unmounted %s (%s)\n", pr->dev, mp); @@ -885,7 +886,7 @@ static int main_hotplug(int argc, char **argv) if (err) ULOG_ERR("umount of %s failed (%d) - %s\n", - mount_point, err, strerror(err)); + mount_point, errno, strerror(errno)); free(mount_point); return 0; @@ -1176,7 +1177,7 @@ static int mount_extroot(char *cfg) if (err) { ULOG_ERR("extroot: mounting %s (%s) on %s failed: %d (%s)\n", - pr->dev, pr->type, path, err, strerror(err)); + pr->dev, pr->type, path, errno, strerror(errno)); } else if (m->overlay) { err = check_extroot(path); if (err)