xfs
[Top] [All Lists]

[PATCH 02/14] xfsprogs: refactor fsrall_cleanup in xfs_fsr

To: xfs@xxxxxxxxxxx
Subject: [PATCH 02/14] xfsprogs: refactor fsrall_cleanup in xfs_fsr
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Tue, 8 Apr 2014 18:24:52 -0500
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1396999504-13769-1-git-send-email-sandeen@xxxxxxxxxx>
References: <1396999504-13769-1-git-send-email-sandeen@xxxxxxxxxx>
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@xxxxxxxxxx>
---
 fsr/xfs_fsr.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 6b5d260..3818f02 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -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);
 }
 
 /*
-- 
1.7.1

<Prev in Thread] Current Thread [Next in Thread>