1 /* Copyright (C) 1991-2003, 2004, 2007, 2009 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 /* 19 * ISO C99 Standard: 7.14 Signal handling <signal.h> 20 */ 21 22 #ifndef _SIGNAL_H 23 24 #if !defined __need_sig_atomic_t && !defined __need_sigset_t 25 # define _SIGNAL_H 26 #endif 27 28 #include <features.h> 29 30 __BEGIN_DECLS 31 32 #include <bits/sigset.h> /* __sigset_t, __sig_atomic_t. */ 33 34 /* An integral type that can be modified atomically, without the 35 possibility of a signal arriving in the middle of the operation. */ 36 #if defined __need_sig_atomic_t || defined _SIGNAL_H 37 # ifndef __sig_atomic_t_defined 38 # define __sig_atomic_t_defined 39 __BEGIN_NAMESPACE_STD 40 typedef __sig_atomic_t sig_atomic_t; 41 __END_NAMESPACE_STD 42 # endif 43 # undef __need_sig_atomic_t 44 #endif 45 46 #if defined __need_sigset_t || (defined _SIGNAL_H && defined __USE_POSIX) 47 # ifndef __sigset_t_defined 48 # define __sigset_t_defined 49 typedef __sigset_t sigset_t; 50 # endif 51 # undef __need_sigset_t 52 #endif 53 54 #ifdef _SIGNAL_H 55 56 #include <bits/types.h> 57 #include <bits/signum.h> 58 59 /* Fake signal functions. */ 60 #define SIG_ERR ((__sighandler_t) -1) /* Error return. */ 61 #define SIG_DFL ((__sighandler_t) 0) /* Default action. */ 62 #define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ 63 #ifdef __USE_UNIX98 64 # define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ 65 #endif 66 /* Biggest signal number + 1 (including real-time signals). */ 67 #ifndef _NSIG /* if arch has not defined it in bits/signum.h... */ 68 # define _NSIG 65 69 #endif 70 #ifdef __USE_MISC 71 # define NSIG _NSIG 72 #endif 73 /* Real-time signal range */ 74 #define SIGRTMIN (__libc_current_sigrtmin()) 75 #define SIGRTMAX (__libc_current_sigrtmax()) 76 /* These are the hard limits of the kernel. These values should not be 77 used directly at user level. */ 78 #ifndef __SIGRTMIN /* if arch has not defined it in bits/signum.h... */ 79 # define __SIGRTMIN 32 80 #endif 81 #define __SIGRTMAX (_NSIG - 1) 82 83 84 #if defined __USE_XOPEN || defined __USE_XOPEN2K 85 # ifndef __pid_t_defined 86 typedef __pid_t pid_t; 87 # define __pid_t_defined 88 # endif 89 #endif 90 #ifdef __USE_XOPEN 91 # ifndef __uid_t_defined 92 typedef __uid_t uid_t; 93 # define __uid_t_defined 94 # endif 95 #endif /* Unix98 */ 96 97 #if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__ 98 /* We need `struct timespec' later on. */ 99 # define __need_timespec 100 # include <time.h> 101 #endif 102 103 #if defined __USE_POSIX199309 || defined __USE_XOPEN_EXTENDED 104 /* Get the `siginfo_t' type plus the needed symbols. */ 105 # include <bits/siginfo.h> 106 #endif 107 108 109 /* Type of a signal handler. */ 110 typedef void (*__sighandler_t) (int); 111 112 #if defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ 113 /* The X/Open definition of `signal' specifies the SVID semantic. Use 114 the additional function `sysv_signal' when X/Open compatibility is 115 requested. */ 116 extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler) 117 __THROW; 118 # ifdef __USE_GNU 119 extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler) 120 __THROW; 121 # endif 122 #endif /* __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ */ 123 124 /* Set the handler for the signal SIG to HANDLER, returning the old 125 handler, or SIG_ERR on error. 126 By default `signal' has the BSD semantic. */ 127 __BEGIN_NAMESPACE_STD 128 #if defined __USE_BSD || !defined __UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL__ 129 extern __sighandler_t signal (int __sig, __sighandler_t __handler) 130 __THROW; 131 libc_hidden_proto(signal) 132 #else 133 /* Make sure the used `signal' implementation is the SVID version. */ 134 # ifdef __REDIRECT_NTH 135 extern __sighandler_t __REDIRECT_NTH (signal, 136 (int __sig, __sighandler_t __handler), 137 __sysv_signal); 138 # else 139 # define signal __sysv_signal 140 # endif 141 #endif 142 __END_NAMESPACE_STD 143 144 #if defined __USE_XOPEN && defined __UCLIBC_SUSV3_LEGACY__ 145 /* The X/Open definition of `signal' conflicts with the BSD version. 146 So they defined another function `bsd_signal'. */ 147 extern __sighandler_t bsd_signal (int __sig, __sighandler_t __handler) 148 __THROW; 149 #endif 150 151 /* Send signal SIG to process number PID. If PID is zero, 152 send SIG to all processes in the current process's process group. 153 If PID is < -1, send SIG to all processes in process group - PID. */ 154 #ifdef __USE_POSIX 155 extern int kill (__pid_t __pid, int __sig) __THROW; 156 libc_hidden_proto(kill) 157 #endif 158 159 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 160 /* Send SIG to all processes in process group PGRP. 161 If PGRP is zero, send SIG to all processes in 162 the current process's process group. */ 163 extern int killpg (__pid_t __pgrp, int __sig) __THROW; 164 #endif 165 166 __BEGIN_NAMESPACE_STD 167 /* Raise signal SIG, i.e., send SIG to yourself. */ 168 extern int raise (int __sig) __THROW; 169 libc_hidden_proto(raise) 170 __END_NAMESPACE_STD 171 172 #if 0 /*def __USE_SVID*/ 173 /* SVID names for the same things. */ 174 extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) 175 __THROW; 176 extern int gsignal (int __sig) __THROW; 177 #endif /* Use SVID. */ 178 179 /* glibc guards the next two wrong with __USE_XOPEN2K */ 180 #if defined __USE_MISC || defined __USE_XOPEN2K8 181 /* Print a message describing the meaning of the given signal number. */ 182 extern void psignal (int __sig, const char *__s); 183 #endif /* Use misc or POSIX 2008. */ 184 185 #if 0 /*def __USE_XOPEN2K8*/ 186 /* Print a message describing the meaning of the given signal information. */ 187 extern void psiginfo (const siginfo_t *__pinfo, const char *__s); 188 #endif /* POSIX 2008. */ 189 190 #ifdef __UCLIBC_SUSV4_LEGACY__ 191 /* The `sigpause' function has two different interfaces. The original 192 BSD definition defines the argument as a mask of the signal, while 193 the more modern interface in X/Open defines it as the signal 194 number. We go with the X/Open version. 195 196 This function is a cancellation point and therefore not marked with 197 __THROW. */ 198 199 # ifdef __USE_XOPEN_EXTENDED 200 /* Remove a signal from the signal mask and suspend the process. */ 201 extern int sigpause(int __sig); 202 # endif 203 #endif /* __UCLIBC_SUSV4_LEGACY__ */ 204 205 #if 0 /*def __USE_BSD*/ 206 /* None of the following functions should be used anymore. They are here 207 only for compatibility. A single word (`int') is not guaranteed to be 208 enough to hold a complete signal mask and therefore these functions 209 simply do not work in many situations. Use `sigprocmask' instead. */ 210 211 /* Compute mask for signal SIG. */ 212 # define sigmask(sig) __sigmask(sig) 213 214 /* Block signals in MASK, returning the old mask. */ 215 extern int sigblock (int __mask) __THROW __attribute_deprecated__; 216 217 /* Set the mask of blocked signals to MASK, returning the old mask. */ 218 extern int sigsetmask (int __mask) __THROW __attribute_deprecated__; 219 220 /* Return currently selected signal mask. */ 221 extern int siggetmask (void) __THROW __attribute_deprecated__; 222 #endif /* Use BSD. */ 223 224 225 #ifdef __USE_GNU 226 typedef __sighandler_t sighandler_t; 227 #endif 228 229 /* 4.4 BSD uses the name `sig_t' for this. */ 230 #ifdef __USE_BSD 231 typedef __sighandler_t sig_t; 232 #endif 233 234 #ifdef __USE_POSIX 235 236 /* Clear all signals from SET. */ 237 extern int sigemptyset (sigset_t *__set) __THROW __nonnull ((1)); 238 239 /* Set all signals in SET. */ 240 extern int sigfillset (sigset_t *__set) __THROW __nonnull ((1)); 241 242 /* Add SIGNO to SET. */ 243 extern int sigaddset (sigset_t *__set, int __signo) __THROW __nonnull ((1)); 244 libc_hidden_proto(sigaddset) 245 246 /* Remove SIGNO from SET. */ 247 extern int sigdelset (sigset_t *__set, int __signo) __THROW __nonnull ((1)); 248 libc_hidden_proto(sigdelset) 249 250 /* Return 1 if SIGNO is in SET, 0 if not. */ 251 extern int sigismember (const sigset_t *__set, int __signo) 252 __THROW __nonnull ((1)); 253 254 # ifdef __USE_GNU 255 /* Return non-empty value is SET is not empty. */ 256 extern int sigisemptyset (const sigset_t *__set) __THROW __nonnull ((1)); 257 258 /* Build new signal set by combining the two inputs set using logical AND. */ 259 extern int sigandset (sigset_t *__set, const sigset_t *__left, 260 const sigset_t *__right) __THROW __nonnull ((1, 2, 3)); 261 262 /* Build new signal set by combining the two inputs set using logical OR. */ 263 extern int sigorset (sigset_t *__set, const sigset_t *__left, 264 const sigset_t *__right) __THROW __nonnull ((1, 2, 3)); 265 # endif /* GNU */ 266 267 /* Get the system-specific definitions of `struct sigaction' 268 and the `SA_*' and `SIG_*'. constants. */ 269 # include <bits/sigaction.h> 270 271 /* Get and/or change the set of blocked signals. */ 272 extern int sigprocmask (int __how, const sigset_t *__restrict __set, 273 sigset_t *__restrict __oset) __THROW; 274 libc_hidden_proto(sigprocmask) 275 276 /* Change the set of blocked signals to SET, 277 wait until a signal arrives, and restore the set of blocked signals. 278 279 This function is a cancellation point and therefore not marked with 280 __THROW. */ 281 extern int sigsuspend (const sigset_t *__set) __nonnull ((1)); 282 #ifdef _LIBC 283 extern __typeof(sigsuspend) __sigsuspend_nocancel attribute_hidden; 284 libc_hidden_proto(sigsuspend) 285 #endif 286 287 /* Get and/or set the action for signal SIG. */ 288 extern int sigaction (int __sig, const struct sigaction *__restrict __act, 289 struct sigaction *__restrict __oact) __THROW; 290 #ifdef _LIBC 291 # if 0 /* this is in headers */ 292 /* In uclibc, userspace struct sigaction is identical to 293 * "new" struct kernel_sigaction (one from the Linux 2.1.68 kernel). 294 * See sigaction.h 295 */ 296 struct old_kernel_sigaction; 297 extern int __syscall_sigaction(int, const struct old_kernel_sigaction *, 298 struct old_kernel_sigaction *) attribute_hidden; 299 # else /* this is how the function is built */ 300 extern __typeof(sigaction) __syscall_sigaction attribute_hidden; 301 # endif 302 # define __need_size_t 303 # include <stddef.h> 304 /* candidate for attribute_hidden, if NPTL would behave */ 305 extern int __syscall_rt_sigaction(int, const struct sigaction *, 306 struct sigaction *, size_t) 307 # ifndef __UCLIBC_HAS_THREADS_NATIVE__ 308 attribute_hidden 309 # endif 310 ; 311 extern __typeof(sigaction) __libc_sigaction; 312 libc_hidden_proto(sigaction) 313 314 # ifdef __mips__ 315 # define _KERNEL_NSIG_WORDS (_NSIG / _MIPS_SZLONG) 316 typedef struct { 317 unsigned long sig[_KERNEL_NSIG_WORDS]; 318 } kernel_sigset_t; 319 # define __SYSCALL_SIGSET_T_SIZE (sizeof(kernel_sigset_t)) 320 # else 321 # define __SYSCALL_SIGSET_T_SIZE (_NSIG / 8) 322 # endif 323 #endif 324 325 /* Put in SET all signals that are blocked and waiting to be delivered. */ 326 extern int sigpending (sigset_t *__set) __THROW __nonnull ((1)); 327 328 329 /* Select any of pending signals from SET or wait for any to arrive. 330 331 This function is a cancellation point and therefore not marked with 332 __THROW. */ 333 extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig) 334 __nonnull ((1, 2)); 335 336 # if defined __USE_POSIX199309 && defined __UCLIBC_HAS_REALTIME__ 337 /* Select any of pending signals from SET and place information in INFO. 338 339 This function is a cancellation point and therefore not marked with 340 __THROW. */ 341 extern int sigwaitinfo (const sigset_t *__restrict __set, 342 siginfo_t *__restrict __info) __nonnull ((1)); 343 #ifdef _LIBC 344 extern __typeof(sigwaitinfo) __sigwaitinfo attribute_hidden; 345 #endif 346 347 /* Select any of pending signals from SET and place information in INFO. 348 Wait the time specified by TIMEOUT if no signal is pending. 349 350 This function is a cancellation point and therefore not marked with 351 __THROW. */ 352 extern int sigtimedwait (const sigset_t *__restrict __set, 353 siginfo_t *__restrict __info, 354 const struct timespec *__restrict __timeout) 355 __nonnull ((1)); 356 #ifdef _LIBC 357 extern __typeof(sigtimedwait) __sigtimedwait_nocancel attribute_hidden; 358 libc_hidden_proto(sigtimedwait) 359 #endif 360 361 /* Send signal SIG to the process PID. Associate data in VAL with the 362 signal. */ 363 extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val) 364 __THROW; 365 # endif /* Use POSIX 199306. */ 366 367 #endif /* Use POSIX. */ 368 369 #ifdef __USE_BSD 370 371 # ifdef __UCLIBC_HAS_SYS_SIGLIST__ 372 /* Names of the signals. This variable exists only for compatibility. 373 Use `strsignal' instead (see <string.h>). */ 374 # define _sys_siglist sys_siglist 375 extern const char *const sys_siglist[_NSIG]; 376 # endif 377 378 #ifndef __UCLIBC_STRICT_HEADERS__ 379 /* Structure passed to `sigvec'. */ 380 struct sigvec 381 { 382 __sighandler_t sv_handler; /* Signal handler. */ 383 int sv_mask; /* Mask of signals to be blocked. */ 384 385 int sv_flags; /* Flags (see below). */ 386 # define sv_onstack sv_flags /* 4.2 BSD compatibility. */ 387 }; 388 389 /* Bits in `sv_flags'. */ 390 # define SV_ONSTACK (1 << 0)/* Take the signal on the signal stack. */ 391 # define SV_INTERRUPT (1 << 1)/* Do not restart system calls. */ 392 # define SV_RESETHAND (1 << 2)/* Reset handler to SIG_DFL on receipt. */ 393 #endif 394 395 /* Get machine-dependent `struct sigcontext' and signal subcodes. */ 396 # include <bits/sigcontext.h> 397 398 #endif /* use BSD. */ 399 400 401 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 402 # define __need_size_t 403 # include <stddef.h> 404 405 # ifdef __UCLIBC_SUSV4_LEGACY__ 406 /* If INTERRUPT is nonzero, make signal SIG interrupt system calls 407 (causing them to fail with EINTR); if INTERRUPT is zero, make system 408 calls be restarted after signal SIG. */ 409 extern int siginterrupt (int __sig, int __interrupt) __THROW; 410 # endif 411 412 # include <bits/sigstack.h> 413 # ifdef __USE_XOPEN 414 /* This will define `ucontext_t' and `mcontext_t'. */ 415 /* SuSv4 obsoleted include/ucontext.h */ 416 # include <sys/ucontext.h> 417 # endif 418 419 # if 0 420 /* Run signals handlers on the stack specified by SS (if not NULL). 421 If OSS is not NULL, it is filled in with the old signal stack status. 422 This interface is obsolete and on many platform not implemented. */ 423 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) 424 __THROW __attribute_deprecated__; 425 # endif 426 427 /* Alternate signal handler stack interface. 428 This interface should always be preferred over `sigstack'. */ 429 extern int sigaltstack (const struct sigaltstack *__restrict __ss, 430 struct sigaltstack *__restrict __oss) __THROW; 431 432 #endif /* use BSD or X/Open Unix. */ 433 434 #if defined __USE_XOPEN_EXTENDED && defined __UCLIBC_HAS_OBSOLETE_BSD_SIGNAL__ 435 /* Simplified interface for signal management. */ 436 437 /* Add SIG to the calling process' signal mask. */ 438 extern int sighold (int __sig) __THROW; 439 440 /* Remove SIG from the calling process' signal mask. */ 441 extern int sigrelse (int __sig) __THROW; 442 443 /* Set the disposition of SIG to SIG_IGN. */ 444 extern int sigignore (int __sig) __THROW; 445 446 /* Set the disposition of SIG. */ 447 extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __THROW; 448 #endif 449 450 #if defined __UCLIBC_HAS_THREADS__ && (defined __USE_POSIX199506 || defined __USE_UNIX98) 451 /* Some of the functions for handling signals in threaded programs must 452 be defined here. */ 453 # include <bits/pthreadtypes.h> 454 # include <bits/sigthread.h> 455 #endif 456 457 /* The following functions are used internally in the C library and in 458 other code which need deep insights. */ 459 460 /* Return number of available real-time signal with highest priority. */ 461 extern int __libc_current_sigrtmin (void) __THROW; 462 /* Return number of available real-time signal with lowest priority. */ 463 extern int __libc_current_sigrtmax (void) __THROW; 464 465 #ifdef _LIBC 466 extern sigset_t _sigintr attribute_hidden; 467 # include <string.h> 468 #endif 469 #endif /* signal.h */ 470 471 __END_DECLS 472 473 #endif /* not signal.h */ 474