Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 30
Examples
SIGJMP_BUF_DEF( ENV );
INT TERMNUM;
PROC MYHANDLER (SIGNO, SIG_INFO, SIG_CONTEXTP);
INT(32) SIGNO; !signal number delivered to this handler
SIGINFO_T SIG_INFO; !NULL
INT .EXT SIG_CONTEXTP( UCONTEXT_T );!pointer to saved
!process execution
!context
BEGIN
STRING BUF [0:40];
STRING .SBUF;
BUF ':=' "Signal " -> @SBUF;
@SBUF := @SBUF [ DNUMOUT( SBUF, SIGNO, 10 ) ];
SBUF ':=' " occurred" -> @SBUF;
CALL WRITE( TERMNUM, BUF, (@SBUF '-' @BUF) '<<' 1);
--Signal-handling code goes here. For example, a
--combination of calls to HIST_* procedures and the
--information provided in SIG_CONTEXTP can be used to
--format and display the execution context of the process
--when the signal occurred.
--SIGLONGJMP_ restores the process execution context
--saved by SIGSETJMP_, which is called from the MAIN
--procedure, and jumps to the location of SIGSETJMP_ with
--a return value of 1.
SIGLONGJMP_( ENV, 1D );
END;
PROC M MAIN;
BEGIN
LITERAL MAXLEN = ZSYS^VAL^LEN^FILENAME;
INT I := 0;
INT LEN;
INT TERMNAME[ 0:MAXLEN-1 ];
! Read startup message
CALL INITIALIZER;
! Install the signal handler
IF SIGACTION_INIT_( @MYHANDLER) <> 0D THEN
; ! Code to handle errors returned by SIGACTION_INIT_
! Open home terminal
CALL PROCESS_GETINFO_( !proc^handle! ,
!proc^descriptor:maxlen! ,
!proc^descriptor^length! ,
!priority! ,
!moms^processhandle! ,
TERMNAME:MAXLEN,
LEN );
CALL FILE_OPEN_( TERMNAME:LEN, TERMNUM );