diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-11 12:16:52 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-11 12:32:34 -0500 |
commit | 695ea13d191c903b86b0d5795a2686a8c6e18015 (patch) | |
tree | 92bdf1115f88cec1e41b5e08bea8bce02dd43981 /exec.c | |
parent | 6ef15e033f997a41c783f87a7084e0aee05c42f9 (diff) | |
download | bfs-695ea13d191c903b86b0d5795a2686a8c6e18015.tar.xz |
exec: Flush I/O streams before executing anything
Otherwise output from commands may appear unexpectedly earlier than
output from bfs. We use fflush(NULL) to flush all streams, which is
more than GNU find does, but seems to be a useful extension.
Diffstat (limited to 'exec.c')
-rw-r--r-- | exec.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -325,6 +325,15 @@ static void bfs_exec_closewd(struct bfs_exec *execbuf, const struct BFTW *ftwbuf /** Actually spawn the process. */ static int bfs_exec_spawn(const struct bfs_exec *execbuf) { + // Before executing anything, flush all open streams. This ensures that + // - the user sees everything relevant before an -ok[dir] prompt + // - output from commands is interleaved consistently with bfs + // - executed commands can rely on I/O from other bfs actions + // + // We do not check errors here, but they will be caught at cleanup time + // with ferror(). + fflush(NULL); + if (execbuf->flags & BFS_EXEC_CONFIRM) { for (size_t i = 0; i < execbuf->argc; ++i) { fprintf(stderr, "%s ", execbuf->argv[i]); |