[hackers] [sbase] find: Flush stdout before executing commands || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 11 Sep 2021 07:54:05 +0200 (CEST)

commit 371f3cb5ec3b8ef3135b3729326bfd6c7b7cb85c
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri Sep 10 22:45:30 2021 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
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
_AT_@ -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:");
Received on Sat Sep 11 2021 - 07:54:05 CEST

This archive was generated by hypermail 2.3.0 : Sat Sep 11 2021 - 08:00:32 CEST