From d0e82db13c6cbb9ea2ae65cf92d79b2984ca98c8 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Mon, 14 Apr 2014 16:12:03 +1000 Subject: [PATCH] xfs_fsr: refactor fsrall_cleanup 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 Reviewed-by: Brian Foster Signed-off-by: Dave Chinner --- fsr/xfs_fsr.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c index 6b5d26090..3818f0236 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); } /* -- 2.47.2