[PATCH] dd: call fsync() only once before exiting if conv=fsync is specified

Rostislav Skudnov rostislav at tuxera.com
Tue Mar 14 16:44:21 UTC 2017


Signed-off-by: Rostislav Skudnov <rostislav at tuxera.com>
---
 coreutils/dd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/coreutils/dd.c b/coreutils/dd.c
index 5e68087..d89c0ae 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -532,17 +532,17 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 			if (write_and_stats(ibuf, n, obs, outfile))
 				goto out_status;
 		}
-
-		if (G.flags & FLAG_FSYNC) {
-			if (fsync(ofd) < 0)
-				goto die_outfile;
-		}
 	}
 
 	if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
 		if (write_and_stats(obuf, oc, obs, outfile))
 			goto out_status;
 	}
+
+	if (G.flags & FLAG_FSYNC) {
+		if (fsync(ofd) < 0)
+			goto die_outfile;
+	}
 	if (close(ifd) < 0) {
  die_infile:
 		bb_simple_perror_msg_and_die(infile);
-- 
2.1.4



More information about the busybox mailing list