scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit e58e69da7f50208398f465eedf152b8c32a49c59
parent 34d94db25f899f209c95262773f60f77b1fb85e0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 11 Jan 2025 10:13:52 +0100

make: Check signals before running actions

In some cases, the next action was executed, so it is safer
to check for signal arrival before executing a new action.

Diffstat:
Msrc/cmd/scc-make/rules.c | 59++++++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/src/cmd/scc-make/rules.c b/src/cmd/scc-make/rules.c @@ -58,6 +58,32 @@ lookup(char *name) } static int +cleanup(Target *tp) +{ + int precious; + Target *p, **q; + + printf("make: signal %d arrived\n", stop); + + precious = 0; + p = lookup(".PRECIOUS"); + for (q = p->deps; q && *q; q++) { + if (strcmp((*q)->name, tp->name) == 0) { + precious = 1; + break; + } + } + + if (!precious && !nflag && !qflag && !is_dir(tp->name)) { + printf("make: trying to remove target %s\n", tp->name); + remove(tp->name); + } + + signal(stop, SIG_DFL); + raise(stop); +} + +static int depends(char *target, char *dep) { int i; @@ -318,7 +344,12 @@ run(Target *tp) } for (i = 0; i < tp->nactions; i++) { - struct action *p = &tp->actions[i]; + struct action *p; + + if (stop) + cleanup(tp); + + p = &tp->actions[i]; debug("executing action '%s'", p->line); s = expandstring(p->line, tp, &p->loc); r = execline(tp, s, ignore, silent); @@ -446,32 +477,6 @@ update(Target *tp) return 0; } -static int -cleanup(Target *tp) -{ - int precious; - Target *p, **q; - - printf("make: signal %d arrived\n", stop); - - precious = 0; - p = lookup(".PRECIOUS"); - for (q = p->deps; q && *q; q++) { - if (strcmp((*q)->name, tp->name) == 0) { - precious = 1; - break; - } - } - - if (!precious && !nflag && !qflag && !is_dir(tp->name)) { - printf("make: trying to remove target %s\n", tp->name); - remove(tp->name); - } - - signal(stop, SIG_DFL); - raise(stop); -} - static int rebuild(Target *tp, int *buildp) {