Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 34
Examples
}
} while ((error = HIST_GETPRIOR_ (&hws)) == HIST_OK);
else
printf ("HIST_INIT_ error: %d. Unable to trace\n",
error);
/* if error != HIST_DONE ... */
SIGJMP_MASKSET_ (jmpEnv, (sigset_t *) 0); /* unblock the
signals */
/* Restore the process execution context (including the
process signal mask) and jump to the location of the
setjmp() call in worker(). */
siglongjmp (jmpEnv, 1);
}
int divider ( int i, int j ) { /* divide i by j */
return ( i/j ); /* When j is zero, and the program was
compiled with the
overflow_traps directive, generates a
SIGFPE signal */
}
void doMoreProcessing ()
{
/* Generate a SIGFPE signal caught by localHandler(). */
divider( 3, 0 );
/* We don't expect divider() to return. */
printf( "doMoreProcessing: after (unexpected) return from
divider()\n" );
}
int worker ()
{
int result;
sig_save_template sigSaveBuf;
if (SIGACTION_SUPPLANT_ (localHandler, &sigSaveBuf,
sigsave_len))
return 1; /* returns 1 for failure */
/* Now we are in the domain of localHandler().*/
if (! setjmp (jmpEnv)) {
/* Normal path: nondeferrable signals are handled by
localHandler(). */
doMoreProcessing ();