commit 371f3cb5ec3b8ef3135b3729326bfd6c7b7cb85c
Author:     Michael Forney <[email protected]>
AuthorDate: Fri Sep 10 22:45:30 2021 -0700
Commit:     Michael Forney <[email protected]>
CommitDate: Fri Sep 10 22:48:47 2021 -0700

    find: Flush stdout before executing commands
    
    The commands may produce output themselves, so this is required to
    ensure that our -print output is actually written before a command's
    output, and also that we don't end up with partially written lines
    due to stdout buffering intermixed with the output of other commands.
    
    Other implementations of find(1) do the same.

diff --git a/find.c b/find.c
index a8404fe..2b5e039 100644
--- a/find.c
+++ b/find.c
@@ -235,6 +235,11 @@ spawn(char *argv[])
        pid_t pid;
        int status;
 
+       /* flush stdout so that -print output always appears before
+        * any output from the command and does not get cut-off in
+        * the middle of a line. */
+       fflush(stdout);
+
        switch((pid = fork())) {
        case -1:
                eprintf("fork:");

Reply via email to