Module Name:    src
Committed By:   rillig
Date:           Fri Jan 29 23:33:24 UTC 2021

Modified Files:
        src/usr.bin/make: job.c

Log Message:
make(1): remove unnecessary fflush for empty shell files

If nothing is done to any file, there is no need to flush stdout.  Move
the call to each of the remaining branches, except for -t mode, where
Job_Touch already takes care of everything.


To generate a diff of this commit:
cvs rdiff -u -r1.400 -r1.401 src/usr.bin/make/job.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.400 src/usr.bin/make/job.c:1.401
--- src/usr.bin/make/job.c:1.400	Fri Jan 29 23:06:41 2021
+++ src/usr.bin/make/job.c	Fri Jan 29 23:33:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.400 2021/01/29 23:06:41 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.401 2021/01/29 23:33:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.400 2021/01/29 23:06:41 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.401 2021/01/29 23:33:24 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1667,13 +1667,16 @@ JobStart(GNode *gn, Boolean special)
 	 * flag *was* given, we just set the file to be stdout. Cute, huh?
 	 */
 	if (Lst_IsEmpty(&gn->commands)) {
-		/* XXX: No need to flush stdout here */
 		job->cmdFILE = stdout;
 		run = FALSE;
 	} else if (((gn->type & OP_MAKE) && !opts.noRecursiveExecute) ||
 	    (!opts.noExecute && !opts.touchFlag)) {
-		/* XXX: The above conditions are needlessly repeated */
+		/*
+		 * XXX: The above conditions seem needlessly repeated but
+		 * are subtly different.
+		 */
 		JobWriteShellCommands(job, gn, cmdsOK, &run);
+		(void)fflush(job->cmdFILE);
 	} else if (!GNode_ShouldExecute(gn)) {
 		/*
 		 * Not executing anything -- just print all the commands to
@@ -1692,6 +1695,7 @@ JobStart(GNode *gn, Boolean special)
 			JobPrintCommands(job);
 		/* Don't execute the shell, thank you. */
 		run = FALSE;
+		(void)fflush(job->cmdFILE);
 	} else {
 		/*
 		 * Just touch the target and note that no shell should be
@@ -1701,8 +1705,6 @@ JobStart(GNode *gn, Boolean special)
 		Job_Touch(gn, job->echo);
 		run = FALSE;
 	}
-	/* Just in case it isn't already... */
-	(void)fflush(job->cmdFILE);
 
 	/* If we're not supposed to execute a shell, don't. */
 	if (!run) {

Reply via email to