public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: linux-ext4@vger.kernel.org
Subject: [PATCH] fuse2fs: return proper exit code from fuse_main
Date: Thu, 11 Oct 2018 15:43:36 +0200	[thread overview]
Message-ID: <20181011134336.977-1-lczerner@redhat.com> (raw)

Currently fuse2fs will always return 0 exit code indicating successful
operation even though the mount failed either because we failed to
properly read the file system in the first place, or the fuse_main()
failed for whatever reason.

Fix it by using the return code from fuse_main(), or return 32 in case
we fail because the file system is corrupted, or we encountered a
problem preventing us mounting the file system. 32 because this is a
libmount exit code indicating mount failed.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 misc/fuse2fs.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 5c73895e..d7a0b668 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3720,7 +3720,7 @@ int main(int argc, char *argv[])
 {
 	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
 	struct fuse2fs fctx;
-	errcode_t err;
+	errcode_t err = 0;
 	char *logfile;
 	char extra_args[BUFSIZ];
 	int ret = 0, flags = EXT2_FLAG_64BITS | EXT2_FLAG_EXCLUSIVE;
@@ -3753,6 +3753,7 @@ int main(int argc, char *argv[])
 		fctx.err_fp = fopen(logfile, "a");
 		if (!fctx.err_fp) {
 			perror(logfile);
+			err = errno;
 			goto out;
 		}
 	} else
@@ -3766,7 +3767,6 @@ int main(int argc, char *argv[])
 	}
 
 	/* Start up the fs (while we still can use stdout) */
-	ret = 2;
 	if (!fctx.ro)
 		flags |= EXT2_FLAG_RW;
 	err = ext2fs_open2(fctx.device, NULL, flags, 0, 0, unix_io_manager,
@@ -3779,8 +3779,6 @@ int main(int argc, char *argv[])
 	fctx.fs = global_fs;
 	global_fs->priv_data = &fctx;
 
-	ret = 3;
-
 	if (ext2fs_has_feature_journal_needs_recovery(global_fs->super)) {
 		if (!fctx.ro) {
 			printf(_("%s: recovering journal\n"), fctx.device);
@@ -3797,6 +3795,7 @@ int main(int argc, char *argv[])
 		} else {
 			printf("%s", _("Journal needs recovery; running "
 			       "`e2fsck -E journal_only' is required.\n"));
+			err = 1;
 			goto out;
 		}
 	}
@@ -3836,6 +3835,7 @@ int main(int argc, char *argv[])
 	if (global_fs->super->s_state & EXT2_ERROR_FS) {
 		printf("%s",
 		       _("Errors detected; running e2fsck is required.\n"));
+		err = 1;
 		goto out;
 	}
 
@@ -3859,11 +3859,16 @@ int main(int argc, char *argv[])
 	}
 
 	pthread_mutex_init(&fctx.bfl, NULL);
-	fuse_main(args.argc, args.argv, &fs_ops, &fctx);
+	ret = fuse_main(args.argc, args.argv, &fs_ops, &fctx);
 	pthread_mutex_destroy(&fctx.bfl);
 
-	ret = 0;
 out:
+	/*
+	 * Encountered error reading the file system. Return standard "mount
+	 * failure" mount exit code (32).
+	 */
+	if (err)
+		ret = 32;
 	if (global_fs) {
 		err = ext2fs_close(global_fs);
 		if (err)
-- 
2.17.1

             reply	other threads:[~2018-10-11 21:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11 13:43 Lukas Czerner [this message]
2018-10-11 15:28 ` [PATCH] fuse2fs: return proper exit code from fuse_main Darrick J. Wong
2018-10-12  5:49   ` Lukas Czerner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181011134336.977-1-lczerner@redhat.com \
    --to=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox