make/src
Paul Smith 26e359c71d [SV 62840] Don't change IO buffering before printing version
If users run 'make --version | head -n1' they expect make to exit
with a success (0) code.  This works because the pipe forces the
default buffering on stdout to be fully buffered so all the output
is printed to the pipe in a single write(2) and won't fail.  However
due to output sync we forcibly set stdout to line buffered, which
means if the reader closes the pipe fast enough make will exit with
an error code because the write to stdout failed.

Move the setup done in output_init() back into main() where it can
be done in a proper order.  Rework the order of operations during
startup so that we check for help and version flags before we change
the buffering.  Clean up the behavior of print_usage().

Original changes from Dmitry Goncharov <dgoncharov@users.sf.net>.

* src/main.c (switches): Don't send --version in the environment.
(print_usage): Add a blank line after the version before the usage.
Move the die() into this function since we always die() afterward.
Note the die will flush so no need to do it explicitly.
(print_version): The caller will fflush when appropriate.
(close_stdout): Move from output.c so it is installed early.
(decode_switches): Only call print_usage on error, not for --help.
(main): Install the close_stdout handler immediately after start.
Move the calls to print_usage() due to --help and --version to be
called immediately after we decode the switches.  Move the buffer set
here from output_init(), immediately after we know we'll be running.
* src/output.c (output_init): Move buffer setting to main().
(close_stdout): Move to main().
2022-08-30 21:04:48 -04:00
..
w32 Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
amiga.c Take advantage of mempcpy() and stpcpy() 2022-07-30 18:40:21 -04:00
amiga.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
ar.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
arscan.c * src/misc.c (make_toui): Parse a string into an unsigned int 2022-06-04 18:34:15 -04:00
commands.c Take advantage of mempcpy() and stpcpy() 2022-07-30 18:40:21 -04:00
commands.h Run autoupdate and clean up autoconf usage 2022-07-09 10:46:47 -04:00
config.ami.template Convert HAVE_GETLOADAVG to HAVE_DECL_GETLOADAVG 2022-07-09 11:09:17 -04:00
config.h-vms.template Support implementing the jobserver using named pipes 2022-08-02 23:36:35 -04:00
config.h.W32.template Support implementing the jobserver using named pipes 2022-08-02 23:36:35 -04:00
configh.dos.template * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
debug.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
default.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
dep.h [SV 62100] Add '--shuffle' option support 2022-06-04 19:04:37 -04:00
dir.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
expand.c Take advantage of mempcpy() and stpcpy() 2022-07-30 18:40:21 -04:00
file.c [SV 62706] Only second-expand targets that might be built 2022-07-30 18:40:28 -04:00
filedef.h [SV 62706] Only second-expand targets that might be built 2022-07-30 18:40:28 -04:00
function.c Disable the jobserver in non-recursive children 2022-07-30 18:40:28 -04:00
getopt1.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
getopt.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
getopt.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
gettext.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
gmk-default.scm * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
gnumake.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
guile.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
hash.c Clean up a few Windows build warnings (not all!) 2021-09-05 21:09:27 -04:00
hash.h hash: Remove unnecessary isupper() check before tolower() 2022-04-24 17:52:54 -04:00
implicit.c Take advantage of mempcpy() and stpcpy() 2022-07-30 18:40:21 -04:00
job.c Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
job.h Run autoupdate and clean up autoconf usage 2022-07-09 10:46:47 -04:00
load.c Remove extraneous characters from fatal() calls 2022-02-27 18:01:13 -05:00
loadapi.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
main.c [SV 62840] Don't change IO buffering before printing version 2022-08-30 21:04:48 -04:00
makeint.h Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
misc.c Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
os.h Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
output.c [SV 62840] Don't change IO buffering before printing version 2022-08-30 21:04:48 -04:00
output.h Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
posixos.c Rework output sync to lock a temp file on POSIX 2022-08-30 15:44:43 -04:00
read.c Replace strcmp() with memcmp() where possible 2022-04-24 17:52:54 -04:00
remake.c [SV 62706] Only second-expand targets that might be built 2022-07-30 18:40:28 -04:00
remote-cstms.c getloadavg: Remove support for privileged invocation 2022-07-09 10:47:13 -04:00
remote-stub.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
rule.c [SV 62206] Fix %-substitution in second expansion of pattern rules 2022-04-24 17:52:07 -04:00
rule.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
shuffle.c [SV 62100] Add '--shuffle' option support 2022-06-04 19:04:37 -04:00
shuffle.h [SV 62100] Add '--shuffle' option support 2022-06-04 19:04:37 -04:00
signame.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
strcache.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
variable.c Disable the jobserver in non-recursive children 2022-07-30 18:40:28 -04:00
variable.h Disable the jobserver in non-recursive children 2022-07-30 18:40:28 -04:00
version.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vms_exit.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vms_export_symbol.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vms_progname.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vmsdir.h * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vmsfunctions.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vmsify.c * <all>: Update copyright notices. 2022-02-10 14:48:26 -05:00
vmsjobs.c Enhance get_tmpfile() and add get_tmppath() 2022-08-02 23:36:35 -04:00
vpath.c Take advantage of mempcpy() and stpcpy() 2022-07-30 18:40:21 -04:00