From: "Darrick J. Wong" <djwong@kernel.org>
To: Theodore Ts'o <tytso@mit.edu>
Cc: Tim Woodall <debianbugs@woodall.me.uk>,
linux-ext4 <linux-ext4@vger.kernel.org>
Subject: [PATCH] fuse2fs: clean up the lockfile handling
Date: Mon, 16 Jun 2025 08:06:14 -0700 [thread overview]
Message-ID: <20250616150614.GG6134@frogsfrogsfrogs> (raw)
From: Darrick J. Wong <djwong@kernel.org>
Fix various problems with the new lockfile code in fuse2fs: the printfs
should use the actual logging function err_printf, the messages should
be looked up in gettext, we should actually exit main properly on
error instead of calling exit(), and the error message printing for the
final lockfile unlink is broken.
Fixes: e83c0df0135f98 ("fuse2fs: rename the inusefile option to lockfile")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 45 +++++++++++++++++++++++++++++----------------
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 0f9cb6849aa7ad..bb75d9421283ed 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4417,19 +4417,31 @@ int main(int argc, char *argv[])
fctx.alloc_all_blocks = 1;
}
- if(fctx.lockfile) {
- FILE* lockfile=fopen(fctx.lockfile, "w");
- if(!lockfile) {
- fprintf(stderr, "Requested lockfile=%s but couldn't open the file for writing\n", fctx.lockfile);
- exit(1);
+ if (fctx.lockfile) {
+ FILE *lockfile = fopen(fctx.lockfile, "w");
+ char *resolved;
+
+ if (!lockfile) {
+ err = errno;
+ err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
+ _("opening lockfile failed"),
+ strerror(err));
+ fctx.lockfile = NULL;
+ ret |= 32;
+ goto out;
}
fclose(lockfile);
- char* resolved = realpath(fctx.lockfile, NULL);
+
+ resolved = realpath(fctx.lockfile, NULL);
if (!resolved) {
- perror("realpath");
- fprintf(stderr, "Could not resolve realpath for lockfile=%s\n", fctx.lockfile);
+ err = errno;
+ err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
+ _("resolving lockfile failed"),
+ strerror(err));
unlink(fctx.lockfile);
- exit(1);
+ fctx.lockfile = NULL;
+ ret |= 32;
+ goto out;
}
free(fctx.lockfile);
fctx.lockfile = resolved;
@@ -4639,14 +4651,15 @@ int main(int argc, char *argv[])
com_err(argv[0], err, "while closing fs");
global_fs = NULL;
}
- if(fctx.lockfile) {
- err = unlink(fctx.lockfile);
- if (err)
- com_err(argv[0], errno, "while unlinking '%s'",
- fctx.lockfile);
- }
- if (fctx.lockfile)
+ if (fctx.lockfile) {
+ if (unlink(fctx.lockfile)) {
+ err = errno;
+ err_printf(&fctx, "%s: %s: %s\n", fctx.lockfile,
+ _("removing lockfile failed"),
+ strerror(err));
+ }
free(fctx.lockfile);
+ }
if (fctx.device)
free(fctx.device);
fuse_opt_free_args(&args);
next reply other threads:[~2025-06-16 15:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 15:06 Darrick J. Wong [this message]
2025-06-26 3:35 ` [PATCH] fuse2fs: clean up the lockfile handling Theodore Ts'o
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=20250616150614.GG6134@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=debianbugs@woodall.me.uk \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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