From 3bf9f42fd409efe80a2cc806287a2e0187592d64 Mon Sep 17 00:00:00 2001 From: apb Date: Sun, 19 Oct 2008 08:30:10 +0000 Subject: [PATCH] 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. --- usr.bin/make/main.c | 30 ++++++++++++++++++------------ usr.bin/make/make.1 | 7 +++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index c75548045d94..680cc525e966 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -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 #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); + } } /*- diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index 16804dce273a..9b5652d340a9 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -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