diff options
| author | martin <martin@NetBSD.org> | 2020-07-07 10:40:46 +0000 |
|---|---|---|
| committer | martin <martin@NetBSD.org> | 2020-07-07 10:40:46 +0000 |
| commit | 742029066e5f2a7988e9d9f07dd048e60f7564df (patch) | |
| tree | 31efeeb3a51cfd81c624a10878f870c2a567543d /usr.bin | |
| parent | 6c9319751981917f76044eb3f84890c7842da295 (diff) | |
Pull up following revision(s) (requested by uwe in ticket #981):
usr.bin/m4/m4.1: revision 1.28
usr.bin/m4/m4.1: revision 1.29
usr.bin/m4/extern.h: revision 1.20
usr.bin/m4/main.c: revision 1.49
usr.bin/m4/m4.1: revision 1.30
usr.bin/m4/trace.c: revision 1.9
usr.bin/m4/main.c: revision 1.50
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.
Fix --error-output to be more like GNU m4.
GNU m4 --error-output is the same as -o despite the name. It does NOT
affect warnings, error messages, and 'errprint' output so drop the
misguided bit of code that tried to freopen stderr without closing it
on failure. Drop -e (which was our local invention) and make merge
--error-output with -o so that both set traceout. Make trace_file()
preserve the old traceout on error and return error status so that the
caller can emit appropriate warning.
Do not yet support disabling tracing with an empty name, the rest of
the code is not ready, we don't do -o positionally and we don't have
`debugfile'.
Fix --error-output to be more like GNU m4. It's a long version of -o.
Bump date for previous.
Use a date that is actually a real date.
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/m4/extern.h | 4 | ||||
| -rw-r--r-- | usr.bin/m4/m4.1 | 9 | ||||
| -rw-r--r-- | usr.bin/m4/main.c | 26 | ||||
| -rw-r--r-- | usr.bin/m4/trace.c | 24 |
4 files changed, 31 insertions, 32 deletions
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 1cb9de13da9..5c73798bd6f 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,5 +1,5 @@ /* $OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $ */ -/* $NetBSD: extern.h,v 1.19 2016/01/16 18:30:57 christos Exp $ */ +/* $NetBSD: extern.h,v 1.19.18.1 2020/07/07 10:40:46 martin Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -146,7 +146,7 @@ extern char *endest; /* trace.c */ extern unsigned int trace_flags; #define TRACE_ALL 512 -extern void trace_file(const char *); +extern int trace_file(const char *); extern size_t trace(const char **, int, struct input_file *); extern void finish_trace(size_t); extern void set_trace_flags(const char *); diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1 index f033cee72bb..ae0c2cbc4f3 100644 --- a/usr.bin/m4/m4.1 +++ b/usr.bin/m4/m4.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: m4.1,v 1.27 2016/01/17 11:24:28 wiz Exp $ +.\" $NetBSD: m4.1,v 1.27.18.1 2020/07/07 10:40:46 martin Exp $ .\" @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $ .\" .\" Copyright (c) 1989, 1993 @@ -31,7 +31,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 16, 2015 +.Dd June 25, 2020 .Dt M4 1 .Os .Sh NAME @@ -46,7 +46,6 @@ .Sm on .Oc .Op Fl d Ar flags -.Op Fl e Ar filename .Op Fl F Ar filename .Op Fl I Ar dirname .Op Fl L Ar number @@ -138,8 +137,6 @@ By default, trace is set to Warnings make .Nm exit. -.It Fl e , Fl Fl error-output Ar filename -Redirect error output to filename. .It Fl F , Fl Fl freeze-state Ar filename Save the input state to .Ar filename . @@ -166,7 +163,7 @@ Set unbuffered output, disable tty signals. .It Fl L , Fl Fl nesting-limit Set the nesting limit in macro expansions. This is unimplemented and unlimited. -.It Fl o Ar filename +.It Fl o , Fl Fl error-output Ar filename Send trace output to .Ar filename . .It Fl P , Fl Fl prefix-builtins diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 2a38bb36686..453c2d3598b 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -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.48.2.1 2020/07/07 10:40:46 martin 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.48.2.1 2020/07/07 10:40:46 martin Exp $"); #include <assert.h> #include <signal.h> #include <getopt.h> @@ -196,7 +196,7 @@ onintr(int signo) struct option longopts[] = { { "debug", optional_argument, 0, 'd' }, { "define", required_argument, 0, 'D' }, - { "error-output", required_argument, 0, 'e' }, + { "error-output", required_argument, 0, 'o' }, /* sic */ { "fatal-warnings", no_argument, 0, 'E' }, { "freeze-state", required_argument, 0, 'F' }, { "gnu", no_argument, 0, 'g' }, @@ -227,8 +227,8 @@ main(int argc, char *argv[]) { int c; int n; + int error; char *p; - FILE *sfp; setprogname(argv[0]); @@ -246,7 +246,7 @@ main(int argc, char *argv[]) outfile = NULL; resizedivs(MAXOUT); - while ((c = getopt_long(argc, argv, "D:d:e:EF:GgI:iL:o:PR:Qst:U:v", + while ((c = getopt_long(argc, argv, "D:d:EF:GgI:iL:o:PR:Qst:U:v", longopts, NULL)) != -1) switch(c) { case 'D': /* define something..*/ @@ -263,18 +263,6 @@ main(int argc, char *argv[]) case 'E': fatal_warnings++; break; - case 'e': - /* - * Don't use freopen here because if it fails - * we lose stderr, instead trash it. - */ - if ((sfp = fopen(optarg, "w+")) == NULL) { - warn("Can't redirect errors to `%s'", optarg); - break; - } - fclose(stderr); - memcpy(stderr, sfp, sizeof(*sfp)); - break; case 'F': freeze = optarg; #ifndef REAL_FREEZE @@ -299,7 +287,9 @@ main(int argc, char *argv[]) nesting_limit = atoi(optarg); break; case 'o': - trace_file(optarg); + error = trace_file(optarg); + if (error) + warn("%s", optarg); break; case 'P': prefix_builtins = 1; diff --git a/usr.bin/m4/trace.c b/usr.bin/m4/trace.c index bb9397fedfe..4d5d48ec4e4 100644 --- a/usr.bin/m4/trace.c +++ b/usr.bin/m4/trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $ */ +/* $NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $ */ /* $OpenBSD: trace.c,v 1.15 2006/03/24 08:03:44 espie Exp $ */ /* * Copyright (c) 2001 Marc Espie. @@ -28,7 +28,7 @@ #include "nbtool_config.h" #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $"); +__RCSID("$NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $"); #include <sys/types.h> #include <err.h> @@ -59,15 +59,27 @@ static int frame_level(void); unsigned int trace_flags = TRACE_QUOTE | TRACE_EXPANSION; -void +int trace_file(const char *name) { + FILE *newfp; + + if (name == NULL) + newfp = stderr; +#if 0 /* not yet */ + else if (*name == '\0') + newfp = NULL; +#endif + else { + newfp = fopen(name, "a"); + if (newfp == NULL) + return -1; + } if (traceout && traceout != stderr) fclose(traceout); - traceout = fopen(name, "w"); - if (!traceout) - err(1, "can't open %s", name); + traceout = newfp; + return 0; } static unsigned int |
