]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_fsr: refactor fsrall_cleanup
authorEric Sandeen <sandeen@redhat.com>
Mon, 14 Apr 2014 06:12:03 +0000 (16:12 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 14 Apr 2014 06:12:03 +0000 (16:12 +1000)
fsrall_cleanup leaked an fd in the non-timeout
case - but the logic was weird and tortured, refactor
it to make more sense and fix the fd leak as well.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fsr/xfs_fsr.c

index 6b5d26090ae97aa57f4305d094efa4406a251401..3818f023627516617508b0b6c4baddadd9c9e7c0 100644 (file)
@@ -647,14 +647,19 @@ fsrall_cleanup(int timeout)
        int ret;
        char buf[SMBUFSZ];
 
-       /* record where we left off */
        unlink(leftofffile);
-       fd = open(leftofffile, O_WRONLY|O_CREAT|O_EXCL, 0644);
-       if (fd == -1)
-               fsrprintf(_("open(%s) failed: %s\n"),
-                         leftofffile, strerror(errno));
-       else {
-               if (timeout) {
+
+       if (timeout) {
+               fsrprintf(_("%s startpass %d, endpass %d, time %d seconds\n"),
+                       progname, startpass, fs->npass,
+                       time(0) - endtime + howlong);
+
+               /* record where we left off */
+               fd = open(leftofffile, O_WRONLY|O_CREAT|O_EXCL, 0644);
+               if (fd == -1) {
+                       fsrprintf(_("open(%s) failed: %s\n"),
+                                 leftofffile, strerror(errno));
+               } else {
                        ret = sprintf(buf, "%s %d %llu\n", fs->dev,
                                fs->npass, (unsigned long long)leftoffino);
                        if (write(fd, buf, ret) < strlen(buf))
@@ -663,11 +668,6 @@ fsrall_cleanup(int timeout)
                        close(fd);
                }
        }
-
-       if (timeout)
-               fsrprintf(_("%s startpass %d, endpass %d, time %d seconds\n"),
-                       progname, startpass, fs->npass,
-                       time(0) - endtime + howlong);
 }
 
 /*