SIG_USR handling seems to be working

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@282 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
stasinos 2002-01-09 17:19:36 +00:00
parent 8496030d8a
commit 7849f7b54e
9 changed files with 89 additions and 7 deletions

View File

@ -874,6 +874,9 @@ InitCodes(void)
AtomArrow = LookupAtom("->");
heap_regs->atom_assert = LookupAtom(":-");
heap_regs->atom_alarm = LookupAtom("$alarm");
#if USE_SIGACTION
heap_regs->atom_sig_pending = LookupAtom("$sig_pending");
#endif
AtomBraces = LookupAtom("{}");
heap_regs->atom_b = LookupAtom("$last_choice_pt");
heap_regs->atom_break = LookupAtom("$break");

View File

@ -1050,6 +1050,9 @@ restore_codes(void)
heap_regs->atom_read = AtomAdjust(heap_regs->atom_read);
heap_regs->atom_repeat = AtomAdjust(heap_regs->atom_repeat);
heap_regs->atom_restore_regs = AtomAdjust(heap_regs->atom_restore_regs);
#if USE_SIGACTION
heap_regs->atom_sig_pending = AtomAdjust(heap_regs->atom_sig_pending);
#endif
heap_regs->atom_stack_free = AtomAdjust(heap_regs->atom_stack_free);
heap_regs->atom_true = AtomAdjust(heap_regs->atom_true);
heap_regs->atom_user = AtomAdjust(heap_regs->atom_user);

View File

@ -823,6 +823,7 @@ STATIC_PROTO (void InitSignals, (void));
STATIC_PROTO (void HandleSIGSEGV, (int, siginfo_t *, ucontext_t *));
STATIC_PROTO (void HandleMatherr, (int, siginfo_t *, ucontext_t *));
STATIC_PROTO (void HandleSIGUSER, (int, siginfo_t *, ucontext_t *));
STATIC_PROTO (void my_signal_info, (int, void (*)(int, siginfo_t *, ucontext_t *)));
STATIC_PROTO (void my_signal, (int, void (*)(int, siginfo_t *, ucontext_t *)));
@ -901,10 +902,11 @@ my_signal(int sig, void (*handler)(int, siginfo_t *, ucontext_t *))
sigaction(sig,&sigact,NULL);
}
#else
#else /* if not (defined(__svr4__) || defined(__SVR4)) */
STATIC_PROTO (RETSIGTYPE HandleMatherr, (int));
STATIC_PROTO (RETSIGTYPE HandleSIGSEGV, (int));
STATIC_PROTO (RETSIGTYPE HandleSIGUSER, (int));
STATIC_PROTO (void my_signal_info, (int, void (*)(int)));
STATIC_PROTO (void my_signal, (int, void (*)(int)));
@ -1051,7 +1053,7 @@ void (*handler)(int);
}
#endif /* __linux__ */
#endif
#endif /* (defined(__svr4__) || defined(__SVR4)) */
static int
@ -1251,6 +1253,37 @@ HandleALRM(int s)
}
#endif
#if USE_SIGACTION
/* this routine is called if YAP received one of the signals that
can be handled by user code, currently SIGUSR1 and SIGUSR2 */
static RETSIGTYPE
#if (defined(__svr4__) || defined(__SVR4))
HandleSIGUSER (int s, siginfo_t *x, ucontext_t *y)
#else
HandleSIGUSER(int s)
#endif
{
/* force the system to creep */
p_creep ();
/* raise the '$sig_pending' flag */
/* NOTE: shouldn't this be a queue? */
switch (s) {
case SIGUSR1:
PutValue(AtomSigPending, MkAtomTerm(LookupAtom("sig_usr1")));
break;
case SIGUSR2:
PutValue(AtomSigPending, MkAtomTerm(LookupAtom("sig_usr2")));
break;
default:
/* should never be here, freak out and die! */
/* YapErrorWhatever(); */
;
}
}
#endif /* USE_SIGACTION */
/*
* This function is called after a normal interrupt had been caught It allows
* 6 possibilities : abort, continue, trace, debug, help, exit
@ -1315,6 +1348,10 @@ InitSignals (void)
#else
my_signal (SIGINT, HandleSIGINT);
#endif
#if USE_SIGACTION
my_signal (SIGUSR1, HandleSIGUSER);
my_signal (SIGUSR2, HandleSIGUSER);
#endif
#ifndef MPW
my_signal (SIGFPE, HandleMatherr);
#endif

View File

@ -10,7 +10,7 @@
* File: Heap.h *
* mods: *
* comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.17 2002-01-07 06:28:03 vsc Exp $ *
* version: $Id: Heap.h,v 1.18 2002-01-09 17:19:36 stasinos Exp $ *
*************************************************************************/
/* information that can be stored in Code Space */
@ -196,6 +196,9 @@ typedef struct various_codes {
atom_read,
atom_repeat,
atom_restore_regs,
#if USE_SIGACTION
atom_sig_pending,
#endif
atom_stack_free,
atom_true,
atom_unwritable,
@ -350,11 +353,9 @@ typedef struct various_codes {
#define AtomCsult heap_regs->atom_csult
#define AtomCut heap_regs->atom_cut
#define AtomCutBy heap_regs->atom_cut_by
#ifdef EUROTRA
#ifdef SFUNC
#if defined(EUROTRA) && defined(SFUNC)
#define AtomDollarUndef heap_regs->atom_dollar_undef
#endif
#endif
#define AtomE heap_regs->atom_e
#define AtomEQ heap_regs->atom_e_q
#define AtomEof heap_regs->atom_eof
@ -387,6 +388,9 @@ typedef struct various_codes {
#define AtomRead heap_regs->atom_read
#define AtomRepeat heap_regs->atom_repeat
#define AtomRestoreRegs heap_regs->atom_restore_regs
#if USE_SIGACTION
#define AtomSigPending heap_regs->atom_sig_pending
#endif
#define AtomStackFree heap_regs->atom_stack_free
#define AtomTrue heap_regs->atom_true
#define AtomUser heap_regs->atom_user

View File

@ -199,4 +199,10 @@
#define USE_GMP 1
#endif
/* Is fflush(NULL) clobbering input streams? */
#undef BROKEN_FFLUSH_NULL
/* Should we do signal handling? */
#if HAVE_SIGNAL_H && HAVE_SIGACTION
#define USE_SIGACTION 1
#endif

View File

@ -94,6 +94,17 @@ true :- true. % otherwise, $$compile will ignore this clause.
'$enter_top_level' :-
'$alarm'(0, _),
fail.
% set the default user signal handlers
'$enter_top_level' :-
( '$recorded'('$sig_handler',_,_) ->
true
;
'$recordz'('$sig_handler',
action(sig_usr1,(format('Received user signal 1~n',[]),halt)), _),
'$recordz'('$sig_handler',
action(sig_usr2,(format('Received user signal 2~n',[]),halt)), _)
),
fail.
'$enter_top_level' :-
'$clean_up_dead_clauses',
fail.

View File

@ -739,6 +739,17 @@ debugging :-
true
),
'$execute'(M:Goal).
'$creep'(G) :-
'$get_value'('$sig_pending', Signal),
\+ Signal = [], !,
'$set_value'('$sig_pending', []),
( '$recorded'('$sig_handler', action(Signal,A),_) ->
'$execute'(A),
G=[M|Goal]
;
true
),
'$execute'(M:Goal).
'$creep'(_) :-
'$get_value'('$throw', true), !,
'$set_value'('$throw', false),

View File

@ -91,7 +91,7 @@ setof(Template, Generator, Set) :-
% And this is bagof
% Either we have excess of variables
% and we need to find the solutions for each instantion
% and we need to find the solutions for each instantiation
% of these variables
bagof(Template, Generator, Bag) :-

View File

@ -231,6 +231,13 @@ alarm(Interval, Goal, Left) :-
'$recordz'('$alarm_handler',M:Goal,_),
'$alarm'(Interval, Left).
on_signal(Signal,OldAction,Action) :-
recorded('$sig_handler', action(Signal,OldAction), Ref),
erase(Ref),
'$current_module'(M),
'$recordz'('$sig_handler', action(Signal,M:Action),Ref2).
%%% Saving and restoring a computation
save(A) :- var(A), !,