Module Name:    src
Committed By:   uwe
Date:           Wed Jun 24 16:49:30 UTC 2020

Modified Files:
        src/usr.bin/m4: main.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/m4/main.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/m4/main.c
diff -u src/usr.bin/m4/main.c:1.48 src/usr.bin/m4/main.c:1.49
--- src/usr.bin/m4/main.c:1.48	Tue Mar 26 16:41:06 2019
+++ src/usr.bin/m4/main.c	Wed Jun 24 16:49:30 2020
@@ -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 @@ main(int argc, char *argv[])
 			}
 			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;

Reply via email to