Always make the debugging output unbuffered; in addition, if debugging

is enabled but debugging output is not directed to stdout, then make
stdout line buffered.

Previously, the code to make debug output unbuffered applied only if
debugging to a file, not if debugging to stdout or stderr.  Making
stdout line buffered when debugging was suggested by Steven Bellovin.
This commit is contained in:
apb 2008-10-19 08:30:10 +00:00
parent e269763779
commit 3bf9f42fd4
2 changed files with 23 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.152 2008/10/18 14:35:32 apb Exp $ */
/* $NetBSD: main.c,v 1.153 2008/10/19 08:30:10 apb Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: main.c,v 1.152 2008/10/18 14:35:32 apb Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.153 2008/10/19 08:30:10 apb Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.152 2008/10/18 14:35:32 apb Exp $");
__RCSID("$NetBSD: main.c,v 1.153 2008/10/19 08:30:10 apb Exp $");
#endif
#endif /* not lint */
#endif
@ -262,16 +262,15 @@ parse_debug_options(const char *argvalue)
fclose(debug_file);
if (*++modules == '+')
mode = "a";
else {
else
mode = "w";
}
if (!strcmp(modules, "stdout")) {
if (strcmp(modules, "stdout") == 0) {
debug_file = stdout;
return;
goto debug_setbuf;
}
if (!strcmp(modules, "stderr")) {
if (strcmp(modules, "stderr") == 0) {
debug_file = stderr;
return;
goto debug_setbuf;
}
len = strlen(modules);
fname = malloc(len + 20);
@ -286,9 +285,7 @@ parse_debug_options(const char *argvalue)
usage();
}
free(fname);
/* Have this non-buffered */
setbuf(debug_file, NULL);
return;
goto debug_setbuf;
default:
(void)fprintf(stderr,
"%s: illegal argument to d option -- %c\n",
@ -296,6 +293,15 @@ parse_debug_options(const char *argvalue)
usage();
}
}
debug_setbuf:
/*
* Make the debug_file unbuffered, and make
* stdout line buffered (unless debugfile == stdout).
*/
setvbuf(debug_file, NULL, _IONBF, 0);
if (debug_file != stdout) {
setvbuf(stdout, NULL, _IOLBF, 0);
}
}
/*-

View File

@ -1,4 +1,4 @@
.\" $NetBSD: make.1,v 1.138 2008/10/18 14:36:40 apb Exp $
.\" $NetBSD: make.1,v 1.139 2008/10/19 08:30:10 apb Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
.\"
.Dd October 18, 2008
.Dd October 19, 2008
.Dt MAKE 1
.Os
.Sh NAME
@ -121,6 +121,9 @@ By default, debugging information is printed to standard output,
but this can be changed using the
Ar F
debugging flag.
The debugging output is always unbuffered; in addition, if debugging
is enabled but debugging output is not directed to standard output,
then the standard output is line buffered.
.Ar Flags
is one or more of the following:
.Bl -tag -width Ds