18 /* This function will cause system calls to be restarted after signal if possible */
19 SLSig_Fun_Type
*SLsignal (int sig
, SLSig_Fun_Type
*f
)
21 #ifdef SLANG_POSIX_SIGNALS
22 struct sigaction old_sa
, new_sa
;
25 /* We want system calls to be interrupted by SIGALRM. */
26 if (sig
== SIGALRM
) return SLsignal_intr (sig
, f
);
29 sigemptyset (&new_sa
.sa_mask
);
30 new_sa
.sa_handler
= f
;
34 new_sa
.sa_flags
|= SA_RESTART
;
37 if (-1 == sigaction (sig
, &new_sa
, &old_sa
))
38 return (SLSig_Fun_Type
*) SIG_ERR
;
40 return old_sa
.sa_handler
;
43 return signal (sig
, f
);
47 /* This function will NOT cause system calls to be restarted after
50 SLSig_Fun_Type
*SLsignal_intr (int sig
, SLSig_Fun_Type
*f
)
52 #ifdef SLANG_POSIX_SIGNALS
53 struct sigaction old_sa
, new_sa
;
55 sigemptyset (&new_sa
.sa_mask
);
56 new_sa
.sa_handler
= f
;
60 new_sa
.sa_flags
|= SA_INTERRUPT
;
63 if (-1 == sigaction (sig
, &new_sa
, &old_sa
))
64 return (SLSig_Fun_Type
*) SIG_ERR
;
66 return old_sa
.sa_handler
;
69 return signal (sig
, f
);
74 /* We are primarily interested in blocking signals that would cause the
75 * application to reset the tty. These include suspend signals and
76 * possibly interrupt signals.
78 #ifdef SLANG_POSIX_SIGNALS
79 static sigset_t Old_Signal_Mask
;
82 static volatile unsigned int Blocked_Depth
;
84 int SLsig_block_signals (void)
86 #ifdef SLANG_POSIX_SIGNALS
91 if (Blocked_Depth
!= 1)
96 #ifdef SLANG_POSIX_SIGNALS
97 sigemptyset (&new_mask
);
99 sigaddset (&new_mask
, SIGQUIT
);
102 sigaddset (&new_mask
, SIGTSTP
);
105 sigaddset (&new_mask
, SIGINT
);
108 sigaddset (&new_mask
, SIGTTIN
);
111 sigaddset (&new_mask
, SIGTTOU
);
114 (void) sigprocmask (SIG_BLOCK
, &new_mask
, &Old_Signal_Mask
);
117 /* Not implemented. */
122 int SLsig_unblock_signals (void)
124 if (Blocked_Depth
== 0)
129 if (Blocked_Depth
!= 0)
132 #ifdef SLANG_POSIX_SIGNALS
133 (void) sigprocmask (SIG_SETMASK
, &Old_Signal_Mask
, NULL
);