From 92a0ea4c8b3a0f032742933b66a044fc64ef0aca Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Tue, 13 Aug 2019 09:28:20 -0400 Subject: [PATCH] mount.ceph: clean up return codes Mount helpers should return a specific mask as the return value so that the caller can interpret what happened. These are detailed in mount(8) and are already defined in mtab.c. Fix the helper to return appropriate error codes for different failure modes. Also, add a goto out target so we can ensure that we do proper cleanup on failure. Signed-off-by: Jeff Layton --- src/mount/mount.ceph.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mount/mount.ceph.c b/src/mount/mount.ceph.c index a7c52a439e8e..fbf3f0046333 100644 --- a/src/mount/mount.ceph.c +++ b/src/mount/mount.ceph.c @@ -339,13 +339,15 @@ int main(int argc, char *argv[]) retval = parse_arguments(argc, argv, &src, &node, &opts); if (retval) { usage(argv[0]); - exit((retval > 0) ? EXIT_SUCCESS : EXIT_FAILURE); + retval = (retval > 0) ? 0 : EX_USAGE; + goto out; } rsrc = mount_resolve_src(src); if (!rsrc) { printf("failed to resolve source\n"); - exit(1); + retval = EX_USAGE; + goto out; } /* Ensure the ceph key_type is available */ @@ -354,13 +356,14 @@ int main(int argc, char *argv[]) popts = parse_options(opts, &flags); if (!popts) { printf("failed to parse ceph_options\n"); - exit(1); + retval = EX_USAGE; + goto out; } block_signals(SIG_BLOCK); if (mount(rsrc, node, "ceph", flags, popts)) { - retval = errno; + retval = EX_FAIL; switch (errno) { case ENODEV: printf("mount error: ceph filesystem not supported by the system\n"); @@ -375,9 +378,9 @@ int main(int argc, char *argv[]) } block_signals(SIG_UNBLOCK); - +out: free(popts); free(rsrc); - exit(retval); + return retval; } -- 2.47.3