trap.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1984-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* make signal traps
*/
#include "make.h"
#include <sig.h>
#endif
struct Alarms_s
{
};
static int signals[] = /* signals to catch */
{
#ifdef SIGILL
#endif
#ifdef SIGIOT
#endif
#ifdef SIGEMT
#endif
#if !DEBUG
#ifdef SIGBUS
#endif
#ifdef SIGSEGV
#endif
#endif
#ifdef SIGUSR1
#endif
#ifdef SIGUSR2
#endif
};
static struct Trap_s
{
int* caught; /* caught signals */
} trap;
/*
* catch and mark interrupts
*/
static void
{
}
/*
* (re)initialize wakeup rule pointers
*/
void
initwakeup(int repeat)
{
register Alarms_t* a;
}
/*
* set next wakeup time
*/
static void
setwakeup(void)
{
register Seconds_t t;
int level;
t = 0;
t = 1;
else
alarm(t);
{
register Alarms_t* a;
{
do
{
error(level, "%6s %s %s", fmtelapsed((a->time >= now) ? (a->time - now) : 0, 1), timestr(tmxsns(a->time, 0)), a->rule->name);
} while (a = a->next);
}
else
}
}
/*
* wakeup in t seconds and make rules in p
* t==0 to drop alarms for list p, all for p==0
*/
void
{
register Alarms_t* a;
register Alarms_t* z;
register Alarms_t* x;
if (t)
{
t += now;
if (!p)
}
if (p)
{
do
{
x = 0;
{
x = a;
if (z)
else
break;
}
if (t)
{
if (!x)
{
if (x = trap.freealarms)
else
}
x->time = t;
x->next = 0;
if (t <= a->time)
{
x->next = a;
break;
}
if (z)
z->next = x;
else
}
} while (p = p->next);
}
{
while (x = a->next)
a = x;
trap.freealarms = a;
}
setwakeup();
}
/*
* initialize the traps
*/
void
inittrap(void)
{
register int i;
memfatal();
for (i = 0; i < elementsof(signals); i++)
}
/*
* handle interrupts
* called by trap() in safe regions
* 0 returned if no interrupts to handle
*/
int
handle(void)
{
register int sig;
register Rule_t* r;
register Alarms_t* a;
char* s;
char* w;
Var_t* v;
Seconds_t t;
return 0;
{
{
/*
* flush the output streams
*/
/*
* continue if already in finish
*/
{
return 0;
}
/*
* check user trap (some cannot be trapped)
*/
w = 0;
if (!state.compileonly)
switch (sig)
{
case SIGALRM:
t = CURSECS;
{
r = a->rule;
trap.freealarms = a;
}
setwakeup();
continue;
default:
{
if (!(r->property & P_functional))
if (r->property & P_functional)
w = v->value;
{
continue;
}
}
/*FALLTHROUGH*/
#ifdef SIGILL
case SIGILL:
#endif
#ifdef SIGIOT
case SIGIOT:
#endif
#ifdef SIGEMT
case SIGEMT:
#endif
#ifdef SIGBUS
case SIGBUS:
#endif
#ifdef SIGSEGV
case SIGSEGV:
#endif
break;
}
/*
* terminate outstanding jobs
*/
terminate();
/*
* the interpreter resumes without exit
*/
if (state.interpreter)
{
return 1;
}
/*
* if external.interrupt=""|"exit" then exit
* otherwise terminate via original signal
*/
if (w && (!*w || streq(w, "exit")))
finish(3);
/*
* shouldn't get here
*/
exit(3);
}
}
return 1;
}