Wed Jun 24 16:49:30 2020 UTC ()
Try not to lose error output with --error-output.

Try to avoid the trap we set up ourselves while avoiding freopen(3).
When exit flushes and closes open streams it may close sfp first and
when it comes about to flush and close stderr, the descriptor is
already gone and we lose any buffered error output.  This actually
happens on some hosts, breaking --trace output used by autoconf.


(uwe)
diff -r1.48 -r1.49 src/usr.bin/m4/main.c

cvs diff -r1.48 -r1.49 src/usr.bin/m4/main.c (expand / switch to context diff)
--- src/usr.bin/m4/main.c 2019/03/26 16:41:06 1.48
+++ src/usr.bin/m4/main.c 2020/06/24 16:49:30 1.49
@@ -1,5 +1,5 @@
 /*	$OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $	*/
-/*	$NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.49 2020/06/24 16:49:30 uwe Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #include "nbtool_config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.49 2020/06/24 16:49:30 uwe Exp $");
 #include <assert.h>
 #include <signal.h>
 #include <getopt.h>
@@ -274,6 +274,17 @@
 			}
 			fclose(stderr);
 			memcpy(stderr, sfp, sizeof(*sfp));
+			/*
+			 * XXX: try to avoid the trap set up by the
+			 * kludge above.  When exit flushes and closes
+			 * open streams it may close sfp first and
+			 * when it comes about to flush and close
+			 * stderr, the descriptor is already gone and
+			 * we lose any buffered output.  This actually
+			 * happens on some hosts, breaking autoconf
+			 * tracing.
+			 */
+			setvbuf(stderr, (char *)NULL, _IOLBF, 0);
 			break;
 		case 'F':
 			freeze = optarg;