ptg10805159
356 Signals Chapter 10
#include <setjmp.h>
int sigsetjmp(sigjmp_bufenv,intsavemask);
Returns: 0 if called directly,nonzero if returning from a call tosiglongjmp
void siglongjmp(sigjmp_bufenv,intval);
The only difference between these functions and thesetjmpandlongjmpfunctions is
thatsigsetjmphas an additional argument. Ifsavemaskis nonzero, thensigsetjmp
also saves the current signal mask of the process inenv.Whensiglongjmpis called, if
theenvargument was saved by a call tosigsetjmpwith a nonzerosavemask,then
siglongjmprestores the saved signal mask.
Example
The program in Figure10.20 demonstrates how the signal mask that is installed by the
system when a signal handler is invoked automatically includes the signal being
caught. This program also illustrates the use of thesigsetjmpandsiglongjmp
functions.
#include "apue.h"
#include <setjmp.h>
#include <time.h>
static void sig_usr1(int);
static void sig_alrm(int);
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjump;
int
main(void)
{
if (signal(SIGUSR1, sig_usr1) == SIG_ERR)
err_sys("signal(SIGUSR1) error");
if (signal(SIGALRM, sig_alrm) == SIG_ERR)
err_sys("signal(SIGALRM) error");
pr_mask("starting main: "); /* Figure 10.14 */
if (sigsetjmp(jmpbuf, 1)) {
pr_mask("ending main: ");
exit(0);
}
canjump = 1; /* now sigsetjmp() is OK */
for ( ; ; )
pause();
}
static void
sig_usr1(int signo)