]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: clean up the lockfile handling
authorDarrick J. Wong <djwong@kernel.org>
Mon, 16 Jun 2025 15:06:14 +0000 (08:06 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 25 Jun 2025 17:46:07 +0000 (13:46 -0400)
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>
Link: https://lore.kernel.org/r/20250616150614.GG6134@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/fuse2fs.c

index 0f9cb6849aa7adcf14bfbd7688c00df9b84d00ba..bb75d9421283ede27ac3d66fda95f948eb73d90a 100644 (file)
@@ -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 @@ out:
                        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);