From 00599d2bc6b42309d188ffeec255d0f9586b202a Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Fri, 2 Mar 2012 10:18:13 +0400 Subject: [PATCH] Make: redirect own error messages to stderr Signed-off-by: Eygene Ryabinkin --- usr.bin/make/job.c | 30 ++++++++++++++++++++---------- 1 files changed, 20 insertions(+), 10 deletions(-) diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index bc1d6a0..ea1199c 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -926,7 +926,7 @@ JobFinish(Job *job, int *status) if (WIFEXITED(*status)) { if (done || DEBUG(JOB)) { - FILE *out; + FILE *out, *errout; if (compatMake && !usePipes && @@ -940,8 +940,10 @@ JobFinish(Job *job, int *status) out = fdopen(job->outFd, "w"); if (out == NULL) Punt("Cannot fdopen"); + errout = out; } else { out = stdout; + errout = stderr; } DEBUGF(JOB, ("Process %jd exited.\n", @@ -962,7 +964,7 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - fprintf(out, "*** [%s] Error code %d%s\n", + fprintf(errout, "*** [%s] Error code %d%s\n", job->node->name, WEXITSTATUS(*status), (job->flags & JOB_IGNERR) ? @@ -977,7 +979,7 @@ JobFinish(Job *job, int *status) } } else if (WIFSIGNALED(*status)) { if (done || DEBUG(JOB) || (WTERMSIG(*status) == SIGCONT)) { - FILE *out; + FILE *out, *errout; if (compatMake && !usePipes && @@ -991,8 +993,10 @@ JobFinish(Job *job, int *status) out = fdopen(job->outFd, "w"); if (out == NULL) Punt("Cannot fdopen"); + errout = out; } else { out = stdout; + errout = stderr; } if (WTERMSIG(*status) == SIGCONT) { @@ -1031,10 +1035,10 @@ JobFinish(Job *job, int *status) MESSAGE(out, job->node); lastNode = job->node; } - fprintf(out, + fprintf(errout, "*** [%s] Signal %d\n", job->node->name, WTERMSIG(*status)); - fflush(out); + fflush(errout); } } } else { @@ -3002,6 +3006,8 @@ Compat_RunCommand(LstNode *cmdNode, GNode *gn) /* NOTREACHED */ } else { + unsigned char need_nl = 0; + if (ps.argv_free) { free(ps.argv[2]); free(ps.argv[1]); @@ -3039,15 +3045,18 @@ Compat_RunCommand(LstNode *cmdNode, GNode *gn) if (status == 0) { return (0); } else { - printf("*** [%s] Error code %d", + fprintf(stderr, + "*** [%s] Error code %d", gn->name, status); + need_nl = 1; } } else if (WIFSTOPPED(reason)) { status = WSTOPSIG(reason); } else { status = WTERMSIG(reason); - printf("*** [%s] Signal %d", + fprintf(stderr, "*** [%s] Signal %d", gn->name, status); + need_nl = 1; } if (ps.errCheck) { @@ -3058,8 +3067,9 @@ Compat_RunCommand(LstNode *cmdNode, GNode *gn) * target, but let * others continue. */ - printf(" (continuing)\n"); - } + fputs(" (continuing)\n", stderr); + } else if (need_nl) + fputc('\n', stderr); return (status); } else { /* @@ -3068,7 +3078,7 @@ Compat_RunCommand(LstNode *cmdNode, GNode *gn) * If we return 0, this will * happen... */ - printf(" (ignored)\n"); + fputs(" (ignored)\n", stderr); return (0); } } -- 1.7.9