summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2012-10-18 17:54:43 +0000
committerespie <espie@openbsd.org>2012-10-18 17:54:43 +0000
commitbe710f6fb8827d26caf92cd1392b0a3ca8094250 (patch)
tree10e70250beef164e415c0e4d68983d936bc44b19
parentSwitch luna88k to timecounters; tested by aoyama@ (diff)
downloadwireguard-openbsd-be710f6fb8827d26caf92cd1392b0a3ca8094250.tar.xz
wireguard-openbsd-be710f6fb8827d26caf92cd1392b0a3ca8094250.zip
numerous error message fixes:
- do ^C checking differently: don't record sent signals, but when jobs die, recheck whether we received/have pending a INT/QUIT/TERM/HUP signal. Then don't display our process group "normally", instead group together everything dying by signal/shell dying by signal (just give the target names). - make certain we always handle signals before dying from "other conditions" - have the parser messages look more like normal messages - remove double error messages from some parser errors - make sure unclosed variables ARE errors when some modifiers are present - keep track of the base directory we're run from, so that submakes can get shortened directories... - make sure the whole error message including silent command fits into a reasonable length. okay millert@
-rw-r--r--usr.bin/make/cond.c7
-rw-r--r--usr.bin/make/engine.c17
-rw-r--r--usr.bin/make/engine.h3
-rw-r--r--usr.bin/make/error.c21
-rw-r--r--usr.bin/make/job.c175
-rw-r--r--usr.bin/make/job.h6
-rw-r--r--usr.bin/make/lowparse.c14
-rw-r--r--usr.bin/make/main.c11
-rw-r--r--usr.bin/make/varmodifiers.c4
9 files changed, 197 insertions, 61 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 12d0ccc9110..cfd72b2fae1 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cond.c,v 1.46 2012/10/11 14:56:17 espie Exp $ */
+/* $OpenBSD: cond.c,v 1.47 2012/10/18 17:54:43 espie Exp $ */
/* $NetBSD: cond.c,v 1.7 1996/11/06 17:59:02 christos Exp $ */
/*
@@ -1164,8 +1164,9 @@ Cond_End(void)
condTop == 0 ? "at least ": "", MAXIF-condTop,
MAXIF-condTop == 1 ? "" : "s");
for (i = MAXIF-1; i >= condTop; i--) {
- fprintf(stderr, "\t at line %lu of %s\n",
- condStack[i].origin.lineno, condStack[i].origin.fname);
+ fprintf(stderr, "\t(%s:%lu)\n",
+ condStack[i].origin.fname,
+ condStack[i].origin.lineno);
}
}
condTop = MAXIF;
diff --git a/usr.bin/make/engine.c b/usr.bin/make/engine.c
index aaeed8f29a1..654fae793e5 100644
--- a/usr.bin/make/engine.c
+++ b/usr.bin/make/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.37 2012/10/09 19:50:44 espie Exp $ */
+/* $OpenBSD: engine.c,v 1.38 2012/10/18 17:54:43 espie Exp $ */
/*
* Copyright (c) 2012 Marc Espie.
*
@@ -611,13 +611,13 @@ job_attach_node(Job *job, GNode *node)
job->exit_type = JOB_EXIT_OKAY;
job->location = NULL;
job->flags = 0;
- job->sent_signal = 0;
}
void
job_handle_status(Job *job, int status)
{
bool silent;
+ int dying;
/* if there's one job running and we don't keep going, no need
* to report right now.
@@ -633,7 +633,13 @@ job_handle_status(Job *job, int status)
/* classify status */
if (WIFEXITED(status)) {
job->code = WEXITSTATUS(status);/* exited */
- if (status != 0) {
+ if (job->code != 0) {
+ /* if we're already dying from that signal, be silent */
+ if (!silent && job->code > 128
+ && job->code <= 128 + _NSIG) {
+ dying = check_dying_signal();
+ silent = dying && job->code == dying + 128;
+ }
if (!silent)
printf("*** Error %d", job->code);
job->exit_type = JOB_EXIT_BAD;
@@ -642,6 +648,11 @@ job_handle_status(Job *job, int status)
} else {
job->exit_type = JOB_SIGNALED;
job->code = WTERMSIG(status); /* signaled */
+ /* if we're already dying from that signal, be silent */
+ if (!silent) {
+ dying = check_dying_signal();
+ silent = dying && job->code == dying;
+ }
if (!silent)
printf("*** Signal %d", job->code);
}
diff --git a/usr.bin/make/engine.h b/usr.bin/make/engine.h
index 31ca704ba11..e820bc1337b 100644
--- a/usr.bin/make/engine.h
+++ b/usr.bin/make/engine.h
@@ -1,6 +1,6 @@
#ifndef ENGINE_H
#define ENGINE_H
-/* $OpenBSD: engine.h,v 1.11 2012/10/06 09:32:40 espie Exp $ */
+/* $OpenBSD: engine.h,v 1.12 2012/10/18 17:54:43 espie Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -97,7 +97,6 @@ struct Job_ {
#define JOB_EXIT_OKAY 0
#define JOB_EXIT_BAD 1
#define JOB_SIGNALED 2
- int sent_signal;
int code; /* exit status or signal code */
LstNode next_cmd; /* Next command to run */
char *cmd; /* Last command run */
diff --git a/usr.bin/make/error.c b/usr.bin/make/error.c
index d9428b1adff..3b346bb5bd0 100644
--- a/usr.bin/make/error.c
+++ b/usr.bin/make/error.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: error.c,v 1.23 2012/10/02 10:29:30 espie Exp $ */
+/* $OpenBSD: error.c,v 1.24 2012/10/18 17:54:43 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
@@ -149,13 +149,19 @@ static void
ParseVErrorInternal(const Location *origin, int type, const char *fmt,
va_list ap)
{
- if (origin->fname)
- (void)fprintf(stderr, "\"%s\", line %lu: ", origin->fname, origin->lineno);
- if (type == PARSE_WARNING)
- (void)fprintf(stderr, "warning: ");
- (void)vfprintf(stderr, fmt, ap);
+ static bool first = true;
+ fprintf(stderr, "*** %s",
+ type == PARSE_WARNING ? "Warning" : "Parse error");
+ if (first) {
+ fprintf(stderr, " in %s: ", Var_Value(".CURDIR"));
+ first = false;
+ } else
+ fprintf(stderr, ": ");
+ vfprintf(stderr, fmt, ap);
va_end(ap);
- (void)fprintf(stderr, "\n");
+ if (origin->fname)
+ fprintf(stderr, " (%s:%lu)", origin->fname, origin->lineno);
+ fprintf(stderr, "\n");
if (type == PARSE_FATAL)
fatal_errors ++;
}
@@ -177,4 +183,3 @@ Parse_Error(int type, const char *fmt, ...)
ParseVErrorInternal(&l, type, fmt, ap);
va_end(ap);
}
-
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 0f76e4f6d43..d97e61c806b 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.130 2012/10/09 19:46:33 espie Exp $ */
+/* $OpenBSD: job.c,v 1.131 2012/10/18 17:54:43 espie Exp $ */
/* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */
/*
@@ -160,6 +160,13 @@ static void kill_with_sudo_maybe(pid_t, int, const char *);
static void debug_kill_printf(const char *, ...);
static void debug_vprintf(const char *, va_list);
static void may_remove_target(Job *);
+static const char *really_kill(Job *, int);
+static void print_error(Job *);
+static void internal_print_errors(void);
+
+static int dying_signal = 0;
+
+const char * basedirectory = NULL;
static void
kill_with_sudo_maybe(pid_t pid, int signo, const char *p)
@@ -190,7 +197,6 @@ static const char *
really_kill(Job *job, int signo)
{
pid_t pid = job->pid;
- job->sent_signal = signo;
if (getpgid(pid) != getpgrp()) {
if (killpg(pid, signo) == 0)
return "group got signal";
@@ -212,9 +218,9 @@ really_kill(Job *job, int signo)
static void
may_remove_target(Job *j)
{
- if ((j->sent_signal == SIGINT || j->sent_signal == SIGQUIT ||
- j->sent_signal == SIGHUP || j->sent_signal == SIGTERM)
- && !noExecute && !Targ_Precious(j->node)) {
+ int dying = check_dying_signal();
+
+ if (dying && !noExecute && !Targ_Precious(j->node)) {
const char *file = Var(TARGET_INDEX, j->node);
int r = eunlink(file);
@@ -225,48 +231,129 @@ may_remove_target(Job *j)
}
}
+static void
+buf_addcurdir(BUFFER *buf)
+{
+ const char *v = Var_Value(".CURDIR");
+ if (basedirectory != NULL) {
+ size_t len = strlen(basedirectory);
+ if (strncmp(basedirectory, v, len) == 0 &&
+ v[len] == '/') {
+ v += len+1;
+ } else if (strcmp(basedirectory, v) == 0) {
+ Buf_AddString(buf, ".");
+ return;
+ }
+ }
+ Buf_AddString(buf, v);
+}
+
+static const char *
+shortened_curdir(void)
+{
+ static BUFFER buf;
+ bool first = true;
+ if (first) {
+ Buf_Init(&buf, 0);
+ buf_addcurdir(&buf);
+ first = false;
+ }
+ return Buf_Retrieve(&buf);
+}
+
+static void
+quick_error(Job *j, int signo, bool first)
+{
+ if (first) {
+ fprintf(stderr, "*** Signal SIG%s", sys_signame[signo]);
+ fprintf(stderr, " in %s (", shortened_curdir());
+ } else
+ fprintf(stderr, " ");
+
+ fprintf(stderr, "%s", j->node->name);
+ free(j->cmd);
+}
+
static void
print_error(Job *j)
{
static bool first = true;
+ BUFFER buf;
+
+ Buf_Init(&buf, 0);
- if (j->exit_type == JOB_EXIT_BAD) {
- fprintf(stderr, "*** Error %d", j->code);
- if (j->sent_signal != 0 && j->code == j->sent_signal + 128)
- fprintf(stderr, " (SIG%s in shell)",
- sys_signame[j->sent_signal]);
- } else if (j->exit_type == JOB_SIGNALED) {
+ if (j->exit_type == JOB_EXIT_BAD)
+ Buf_printf(&buf, "*** Error %d", j->code);
+ else if (j->exit_type == JOB_SIGNALED) {
if (j->code < NSIG)
- fprintf(stderr, "*** Signal SIG%s",
+ Buf_printf(&buf, "*** Signal SIG%s",
sys_signame[j->code]);
else
- fprintf(stderr, "*** unknown signal %d", j->code);
+ Buf_printf(&buf, "*** unknown signal %d", j->code);
} else
- fprintf(stderr, "*** Should not happen %d", j->code);
+ Buf_printf(&buf, "*** Should not happen %d/%d",
+ j->exit_type, j->code);
if (DEBUG(KILL) && (j->flags & JOB_LOST))
- fprintf(stderr, "!");
+ Buf_AddChar(&buf, '!');
if (first) {
- fprintf(stderr, " in %s", Var_Value(".CURDIR"));
+ Buf_AddString(&buf, " in ");
+ buf_addcurdir(&buf);
first = false;
}
- fprintf(stderr, " (%s:%lu", j->location->fname, j->location->lineno);
- fprintf(stderr, " '%s'", j->node->name);
- if ((j->flags & (JOB_SILENT | JOB_IS_EXPENSIVE)) == JOB_SILENT)
- fprintf(stderr, ": %.120s%s", j->cmd,
- strlen(j->cmd) > 120 ? "..." : "");
- fprintf(stderr, ")\n");
+ Buf_printf(&buf, " (%s:%lu", j->location->fname, j->location->lineno);
+ Buf_printf(&buf, " '%s'", j->node->name);
+ if ((j->flags & (JOB_SILENT | JOB_IS_EXPENSIVE)) == JOB_SILENT
+ && Buf_Size(&buf) < 140) {
+ size_t len = strlen(j->cmd);
+ Buf_AddString(&buf, ": ");
+ if (len + Buf_Size(&buf) < 140)
+ Buf_AddString(&buf, j->cmd);
+ else {
+ Buf_AddChars(&buf, 140 - Buf_Size(&buf), j->cmd);
+ Buf_AddString(&buf, "...");
+ }
+ }
+ fprintf(stderr, "%s)\n", Buf_Retrieve(&buf));
+ Buf_Destroy(&buf);
free(j->cmd);
- may_remove_target(j);
}
+static void
+quick_summary(int signo)
+{
+ Job *j, *k, *jnext;
+ bool first = true;
-void
-print_errors(void)
+ k = errorJobs;
+ errorJobs = NULL;
+ for (j = k; j != NULL; j = jnext) {
+ jnext = j->next;
+ if ((j->exit_type == JOB_EXIT_BAD && j->code == signo+128) ||
+ (j->exit_type == JOB_SIGNALED && j->code == signo)) {
+ quick_error(j, signo, first);
+ first = false;
+ } else {
+ j->next = errorJobs;
+ errorJobs = j;
+ }
+ }
+ if (!first)
+ fprintf(stderr, ")\n");
+}
+
+static void
+internal_print_errors()
{
Job *j, *k, *jnext;
+ int dying;
if (!errorJobs)
- fprintf(stderr, "Stop in %s.\n", Var_Value(".CURDIR"));
+ fprintf(stderr, "Stop in %s.\n", shortened_curdir());
+ for (j = errorJobs; j != NULL; j = j->next)
+ may_remove_target(j);
+ dying = check_dying_signal();
+ if (dying)
+ quick_summary(dying);
while (errorJobs != NULL) {
k = errorJobs;
errorJobs = NULL;
@@ -282,6 +369,13 @@ print_errors(void)
}
}
+void
+print_errors(void)
+{
+ handle_all_signals();
+ internal_print_errors();
+}
+
static void
setup_signal(int sig)
{
@@ -356,7 +450,9 @@ handle_siginfo(void)
if (length == 0) {
Buf_Init(&buf, 0);
- Buf_printf(&buf, "%s in %s: ", Var_Value("MAKE"), Var_Value(".CURDIR"));
+ Buf_printf(&buf, "%s in ", Var_Value("MAKE"));
+ buf_addcurdir(&buf);
+ Buf_AddString(&buf, ": ");
length = Buf_Size(&buf);
} else
Buf_Truncate(&buf, length);
@@ -372,6 +468,24 @@ handle_siginfo(void)
fputs(Buf_Retrieve(&buf), stderr);
}
+int
+check_dying_signal(void)
+{
+ sigset_t set;
+ if (dying_signal)
+ return dying_signal;
+ sigpending(&set);
+ if (got_SIGINT || sigismember(&set, SIGINT))
+ return dying_signal = SIGINT;
+ if (got_SIGHUP || sigismember(&set, SIGHUP))
+ return dying_signal = SIGHUP;
+ if (got_SIGQUIT || sigismember(&set, SIGQUIT))
+ return dying_signal = SIGQUIT;
+ if (got_SIGTERM || sigismember(&set, SIGTERM))
+ return dying_signal = SIGTERM;
+ return 0;
+}
+
void
handle_all_signals(void)
{
@@ -729,7 +843,6 @@ void
handle_running_jobs(void)
{
sigset_t old;
-
/* reaping children in the presence of caught signals */
/* first, we make sure to hold on new signals, to synchronize
@@ -826,7 +939,7 @@ handle_fatal_signal(int signo)
debug_kill_printf("handle_fatal_signal(%d) called.\n", signo);
-
+ dying_signal = signo;
for (job = runningJobs; job != NULL; job = job->next) {
debug_kill_printf("passing to "
"child %ld running %s: %s\n", (long)job->pid,
@@ -842,7 +955,7 @@ handle_fatal_signal(int signo)
}
}
loop_handle_running_jobs();
- print_errors();
+ internal_print_errors();
/* die by that signal */
sigprocmask(SIG_BLOCK, &sigset, NULL);
@@ -850,6 +963,8 @@ handle_fatal_signal(int signo)
kill(getpid(), signo);
sigprocmask(SIG_SETMASK, &emptyset, NULL);
/*NOTREACHED*/
+ fprintf(stderr, "This should never happen\n");
+ exit(1);
}
/*
diff --git a/usr.bin/make/job.h b/usr.bin/make/job.h
index 1ad6cfb546e..22f1115875f 100644
--- a/usr.bin/make/job.h
+++ b/usr.bin/make/job.h
@@ -1,7 +1,7 @@
#ifndef _JOB_H_
#define _JOB_H_
-/* $OpenBSD: job.h,v 1.27 2012/10/02 10:29:31 espie Exp $ */
+/* $OpenBSD: job.h,v 1.28 2012/10/18 17:54:43 espie Exp $ */
/* $NetBSD: job.h,v 1.5 1996/11/06 17:59:10 christos Exp $ */
/*
@@ -62,4 +62,8 @@ extern void determine_expensive_job(Job *);
extern Job *runningJobs, *errorJobs;
extern void debug_job_printf(const char *, ...);
extern void handle_one_job(Job *);
+extern int check_dying_signal(void);
+
+extern const char *basedirectory;
+
#endif /* _JOB_H_ */
diff --git a/usr.bin/make/lowparse.c b/usr.bin/make/lowparse.c
index 405fde58fe2..277e07a2623 100644
--- a/usr.bin/make/lowparse.c
+++ b/usr.bin/make/lowparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lowparse.c,v 1.30 2012/10/02 10:29:31 espie Exp $ */
+/* $OpenBSD: lowparse.c,v 1.31 2012/10/18 17:54:43 espie Exp $ */
/* low-level parsing functions. */
@@ -279,11 +279,9 @@ Parse_ReadNextConditionalLine(Buffer linebuf)
if (c == '\n')
current->origin.lineno++;
}
- if (c == EOF) {
- Parse_Error(PARSE_FATAL,
- "Unclosed conditional");
+ if (c == EOF)
+ /* Unclosed conditional, reported by cond.c */
return NULL;
- }
}
current->origin.lineno++;
}
@@ -489,10 +487,8 @@ Parse_FillLocation(Location *origin)
void
Parse_ReportErrors(void)
{
- if (fatal_errors) {
- fprintf(stderr,
- "Fatal errors encountered -- cannot continue\n");
+ if (fatal_errors)
exit(1);
- } else
+ else
assert(current == NULL);
}
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 14638c258ce..44b7b697406 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.99 2012/10/09 19:47:09 espie Exp $ */
+/* $OpenBSD: main.c,v 1.100 2012/10/18 17:54:43 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -124,9 +124,10 @@ static void read_all_make_rules(bool, bool, Lst, struct dirs *);
static void read_makefile_list(Lst, struct dirs *);
static int ReadMakefile(void *, void *);
-static void record_option(int c, const char *arg)
+static void
+record_option(int c, const char *arg)
{
- char opt[3];
+ char opt[3];
opt[0] = '-';
opt[1] = c;
@@ -724,6 +725,10 @@ main(int argc, char **argv)
* First snag any flags out of the MAKEFLAGS environment variable.
*/
Main_ParseArgLine(getenv("MAKEFLAGS"));
+
+ basedirectory = getenv("MAKEBASEDIRECTORY");
+ if (basedirectory == NULL)
+ setenv("MAKEBASEDIRECTORY", d.current, 0);
MainParseArgs(argc, argv);
diff --git a/usr.bin/make/varmodifiers.c b/usr.bin/make/varmodifiers.c
index 6cd4a94d044..450d4a869d9 100644
--- a/usr.bin/make/varmodifiers.c
+++ b/usr.bin/make/varmodifiers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: varmodifiers.c,v 1.32 2012/10/12 13:20:11 espie Exp $ */
+/* $OpenBSD: varmodifiers.c,v 1.33 2012/10/18 17:54:43 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
@@ -1514,7 +1514,7 @@ VarModifiers_Apply(char *str, const struct Name *name, SymTable *ctxt,
printf("Result is \"%s\"\n", str);
}
if (*tstr == '\0')
- Error("Unclosed variable specification");
+ Parse_Error(PARSE_FATAL, "Unclosed variable specification");
else
tstr++;