Mercurial > hg > octave-nkf > gnulib-hg
comparison lib/sigprocmask.c @ 10689:5fbf24129e48
Take into account the role of SIGABRT_COMPAT on Windows 2008.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 21 Oct 2008 01:12:33 +0200 |
parents | 5a24031ebf7d |
children | e8d2c6fc33ad |
comparison
equal
deleted
inserted
replaced
10688:989b49566cae | 10689:5fbf24129e48 |
---|---|
39 #ifndef SIGKILL | 39 #ifndef SIGKILL |
40 # define SIGKILL (-1) | 40 # define SIGKILL (-1) |
41 #endif | 41 #endif |
42 #ifndef SIGSTOP | 42 #ifndef SIGSTOP |
43 # define SIGSTOP (-1) | 43 # define SIGSTOP (-1) |
44 #endif | |
45 | |
46 /* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias | |
47 for the signal SIGABRT. Only one signal handler is stored for both | |
48 SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */ | |
49 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | |
50 # undef SIGABRT_COMPAT | |
51 # define SIGABRT_COMPAT 6 | |
52 #endif | |
53 #ifdef SIGABRT_COMPAT | |
54 # define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT) | |
55 #else | |
56 # define SIGABRT_COMPAT_MASK 0 | |
44 #endif | 57 #endif |
45 | 58 |
46 typedef void (*handler_t) (int); | 59 typedef void (*handler_t) (int); |
47 | 60 |
48 /* Handling of gnulib defined signals. */ | 61 /* Handling of gnulib defined signals. */ |
72 | 85 |
73 int | 86 int |
74 sigismember (const sigset_t *set, int sig) | 87 sigismember (const sigset_t *set, int sig) |
75 { | 88 { |
76 if (sig >= 0 && sig < NSIG) | 89 if (sig >= 0 && sig < NSIG) |
77 return (*set >> sig) & 1; | 90 { |
91 #ifdef SIGABRT_COMPAT | |
92 if (sig == SIGABRT_COMPAT) | |
93 sig = SIGABRT; | |
94 #endif | |
95 | |
96 return (*set >> sig) & 1; | |
97 } | |
78 else | 98 else |
79 return 0; | 99 return 0; |
80 } | 100 } |
81 | 101 |
82 int | 102 int |
89 int | 109 int |
90 sigaddset (sigset_t *set, int sig) | 110 sigaddset (sigset_t *set, int sig) |
91 { | 111 { |
92 if (sig >= 0 && sig < NSIG) | 112 if (sig >= 0 && sig < NSIG) |
93 { | 113 { |
114 #ifdef SIGABRT_COMPAT | |
115 if (sig == SIGABRT_COMPAT) | |
116 sig = SIGABRT; | |
117 #endif | |
118 | |
94 *set |= 1U << sig; | 119 *set |= 1U << sig; |
95 return 0; | 120 return 0; |
96 } | 121 } |
97 else | 122 else |
98 { | 123 { |
104 int | 129 int |
105 sigdelset (sigset_t *set, int sig) | 130 sigdelset (sigset_t *set, int sig) |
106 { | 131 { |
107 if (sig >= 0 && sig < NSIG) | 132 if (sig >= 0 && sig < NSIG) |
108 { | 133 { |
134 #ifdef SIGABRT_COMPAT | |
135 if (sig == SIGABRT_COMPAT) | |
136 sig = SIGABRT; | |
137 #endif | |
138 | |
109 *set &= ~(1U << sig); | 139 *set &= ~(1U << sig); |
110 return 0; | 140 return 0; |
111 } | 141 } |
112 else | 142 else |
113 { | 143 { |
114 errno = EINVAL; | 144 errno = EINVAL; |
115 return -1; | 145 return -1; |
116 } | 146 } |
117 } | 147 } |
118 | 148 |
149 | |
119 int | 150 int |
120 sigfillset (sigset_t *set) | 151 sigfillset (sigset_t *set) |
121 { | 152 { |
122 *set = (2U << (NSIG - 1)) - 1; | 153 *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK; |
123 return 0; | 154 return 0; |
124 } | 155 } |
125 | 156 |
126 /* Set of currently blocked signals. */ | 157 /* Set of currently blocked signals. */ |
127 static volatile sigset_t blocked_set /* = 0 */; | 158 static volatile sigset_t blocked_set /* = 0 */; |
239 /* We must provide a wrapper, so that a user can query what handler | 270 /* We must provide a wrapper, so that a user can query what handler |
240 they installed even if that signal is currently blocked. */ | 271 they installed even if that signal is currently blocked. */ |
241 if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP | 272 if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP |
242 && handler != SIG_ERR) | 273 && handler != SIG_ERR) |
243 { | 274 { |
275 #ifdef SIGABRT_COMPAT | |
276 if (sig == SIGABRT_COMPAT) | |
277 sig = SIGABRT; | |
278 #endif | |
279 | |
244 if (blocked_set & (1U << sig)) | 280 if (blocked_set & (1U << sig)) |
245 { | 281 { |
246 /* POSIX states that sigprocmask and signal are both | 282 /* POSIX states that sigprocmask and signal are both |
247 async-signal-safe. This is not true of our | 283 async-signal-safe. This is not true of our |
248 implementation - there is a slight data race where an | 284 implementation - there is a slight data race where an |