]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mount.ceph: clean up return codes
authorJeff Layton <jlayton@redhat.com>
Tue, 13 Aug 2019 13:28:20 +0000 (09:28 -0400)
committerNathan Cutler <ncutler@suse.com>
Thu, 14 Nov 2019 16:22:31 +0000 (17:22 +0100)
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 <jlayton@redhat.com>
(cherry picked from commit 92a0ea4c8b3a0f032742933b66a044fc64ef0aca)

src/mount/mount.ceph.c

index 470338d5643354cb852e8c3132b5c90518e57beb..ac00be9db1d5cf240e5c7cb2abe25a7c775ab916 100644 (file)
@@ -335,13 +335,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 */
@@ -350,13 +352,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");
@@ -371,9 +374,9 @@ int main(int argc, char *argv[])
        }
 
        block_signals(SIG_UNBLOCK);
-
+out:
        free(popts);
        free(rsrc);
-       exit(retval);
+       return retval;
 }