summaryrefslogtreecommitdiffstats
path: root/sys-utils/fstrim.c
diff options
context:
space:
mode:
authorKarel Zak2018-04-06 12:53:18 +0200
committerKarel Zak2018-04-06 12:53:18 +0200
commit7afdbb6f0760952c6e4f86d4c73442d1caee96a8 (patch)
tree3eeb8a0c35c652505aa1ce97d2c8f9d200a00a29 /sys-utils/fstrim.c
parentdmesg: fix raw output (diff)
downloadkernel-qcow2-util-linux-7afdbb6f0760952c6e4f86d4c73442d1caee96a8.tar.gz
kernel-qcow2-util-linux-7afdbb6f0760952c6e4f86d4c73442d1caee96a8.tar.xz
kernel-qcow2-util-linux-7afdbb6f0760952c6e4f86d4c73442d1caee96a8.zip
fstrim: Return EXIT_FAILURE when FTRIM ioctl fails
commit 36c370cbf1481aa8724dff8b7b7fec4a8ba9930b adds fstrim_filesystem() that return -1 or 1 depending on the FTRIM ioctl failures. The fstrim_filesystem() return codes should not be used as exit codes. Reported-by: Gwendal Grignou <gwendal@chromium.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/fstrim.c')
-rw-r--r--sys-utils/fstrim.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index ce52063e1..70870ef69 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -241,7 +241,7 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose)
if (cnt && cnt_err)
return MNT_EX_SOMEOK; /* some ok */
- return EXIT_SUCCESS;
+ return MNT_EX_SUCCESS;
}
static void __attribute__((__noreturn__)) usage(void)
@@ -336,14 +336,11 @@ int main(int argc, char **argv)
}
if (all)
- rc = fstrim_all(&range, verbose);
- else {
- rc = fstrim_filesystem(path, &range, verbose);
- if (rc == 1) {
- warnx(_("%s: the discard operation is not supported"), path);
- rc = EXIT_FAILURE;
- }
- }
+ return fstrim_all(&range, verbose); /* MNT_EX_* codes */
- return rc;
+ rc = fstrim_filesystem(path, &range, verbose);
+ if (rc == 1)
+ warnx(_("%s: the discard operation is not supported"), path);
+
+ return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}