comparison src/msdos.c @ 16872:1efa81ac7e5a

* (sigprocmask, sig_suspender): New functions, implement signal blocking on MSDOS.
author Eli Zaretskii <eliz@gnu.org>
date Thu, 16 Jan 1997 12:50:00 +0000
parents 45a12f628d3f
children 8d28d96f6031
comparison
equal deleted inserted replaced
16871:45a12f628d3f 16872:1efa81ac7e5a
67 #endif 67 #endif
68 68
69 #if __DJGPP__ > 1 69 #if __DJGPP__ > 1
70 70
71 #include <signal.h> 71 #include <signal.h>
72 #include "syssignal.h"
72 73
73 #ifndef SYSTEM_MALLOC 74 #ifndef SYSTEM_MALLOC
74 75
75 #ifdef GNU_MALLOC 76 #ifdef GNU_MALLOC
76 77
3142 fork () { return 0; } 3143 fork () { return 0; }
3143 int kill (x, y) int x, y; { return -1; } 3144 int kill (x, y) int x, y; { return -1; }
3144 nice (p) int p; {} 3145 nice (p) int p; {}
3145 void volatile pause () {} 3146 void volatile pause () {}
3146 sigsetmask (x) int x; { return 0; } 3147 sigsetmask (x) int x; { return 0; }
3148 sigblock (mask) int mask; { return 0; }
3147 #endif 3149 #endif
3148 3150
3149 request_sigio () {} 3151 request_sigio () {}
3150 setpgrp () {return 0; } 3152 setpgrp () {return 0; }
3151 setpriority (x,y,z) int x,y,z; { return 0; } 3153 setpriority (x,y,z) int x,y,z; { return 0; }
3154 unrequest_sigio () {}
3155
3156 #if __DJGPP__ > 1
3157
3158 #ifdef POSIX_SIGNALS
3159
3160 /* Augment DJGPP library POSIX signal functions. This is needed
3161 as of DJGPP v2.01, but might be in the library in later releases. */
3162
3163 #include <libc/bss.h>
3164
3165 /* A counter to know when to re-initialize the static sets. */
3166 static int sigprocmask_count = -1;
3167
3168 /* Which signals are currently blocked (initially none). */
3169 static sigset_t current_mask;
3170
3171 /* Which signals are pending (initially none). */
3172 static sigset_t pending_signals;
3173
3174 /* Previous handlers to restore when the blocked signals are unblocked. */
3175 typedef void (*sighandler_t)(int);
3176 static sighandler_t prev_handlers[320];
3177
3178 /* A signal handler which just records that a signal occured
3179 (it will be raised later, if and when the signal is unblocked). */
3180 static void
3181 sig_suspender (signo)
3182 int signo;
3183 {
3184 sigaddset (&pending_signals, signo);
3185 }
3186
3187 int
3188 sigprocmask (how, new_set, old_set)
3189 int how;
3190 const sigset_t *new_set;
3191 sigset_t *old_set;
3192 {
3193 int signo;
3194 sigset_t new_mask;
3195
3196 /* If called for the first time, initialize. */
3197 if (sigprocmask_count != __bss_count)
3198 {
3199 sigprocmask_count = __bss_count;
3200 sigemptyset (&pending_signals);
3201 sigemptyset (&current_mask);
3202 for (signo = 0; signo < 320; signo++)
3203 prev_handlers[signo] = SIG_ERR;
3204 }
3205
3206 if (old_set)
3207 *old_set = current_mask;
3208
3209 if (new_set == 0)
3210 return 0;
3211
3212 if (how != SIG_BLOCK && how != SIG_UNBLOCK && how != SIG_SETMASK)
3213 {
3214 errno = EINVAL;
3215 return -1;
3216 }
3217
3218 sigemptyset (&new_mask);
3219
3220 /* DJGPP supports upto 320 signals. */
3221 for (signo = 0; signo < 320; signo++)
3222 {
3223 if (sigismember (&current_mask, signo))
3224 sigaddset (&new_mask, signo);
3225 else if (sigismember (new_set, signo) && how != SIG_UNBLOCK)
3226 {
3227 sigaddset (&new_mask, signo);
3228
3229 /* SIGKILL is silently ignored, as on other platforms. */
3230 if (signo != SIGKILL && prev_handlers[signo] == SIG_ERR)
3231 prev_handlers[signo] = signal (signo, sig_suspender);
3232 }
3233 if (( how == SIG_UNBLOCK
3234 && sigismember (&new_mask, signo)
3235 && sigismember (new_set, signo))
3236 || (how == SIG_SETMASK
3237 && sigismember (&new_mask, signo)
3238 && !sigismember (new_set, signo)))
3239 {
3240 sigdelset (&new_mask, signo);
3241 if (prev_handlers[signo] != SIG_ERR)
3242 {
3243 signal (signo, prev_handlers[signo]);
3244 prev_handlers[signo] = SIG_ERR;
3245 }
3246 if (sigismember (&pending_signals, signo))
3247 {
3248 sigdelset (&pending_signals, signo);
3249 raise (signo);
3250 }
3251 }
3252 }
3253 current_mask = new_mask;
3254 return 0;
3255 }
3256
3257 #else /* not POSIX_SIGNALS */
3258
3259 sigsetmask (x) int x; { return 0; }
3152 sigblock (mask) int mask; { return 0; } 3260 sigblock (mask) int mask; { return 0; }
3153 unrequest_sigio () {} 3261
3262 #endif /* not POSIX_SIGNALS */
3263 #endif /* __DJGPP__ > 1 */
3154 3264
3155 #ifndef HAVE_SELECT 3265 #ifndef HAVE_SELECT
3156 #include "sysselect.h" 3266 #include "sysselect.h"
3157 3267
3158 #ifndef EMACS_TIME_ZERO_OR_NEG_P 3268 #ifndef EMACS_TIME_ZERO_OR_NEG_P