1 /* 2 * Copyright 2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <signal.h> 11 12 #include <errno.h> 13 14 #include <pthread_private.h> 15 #include <signal_defs.h> 16 #include <syscalls.h> 17 #include <syscall_utils.h> 18 19 20 int 21 sigsetmask(int mask) 22 { 23 sigset_t set = mask; 24 sigset_t oset; 25 26 if (sigprocmask(SIG_SETMASK, &set, &oset) < 0) 27 return -1; 28 29 return (int)oset; 30 } 31 32 33 int 34 sigblock(int mask) 35 { 36 sigset_t set = mask; 37 sigset_t oset; 38 39 if (sigprocmask(SIG_BLOCK, &set, &oset) < 0) 40 return -1; 41 42 return (int)oset; 43 } 44 45 46 int 47 pthread_sigqueue(pthread_t thread, int sig, const union sigval userValue) 48 { 49 status_t error; 50 if (signal < 0) 51 RETURN_AND_SET_ERRNO(EINVAL); 52 53 error = _kern_send_signal(thread->id, sig, &userValue, 54 SIGNAL_FLAG_SEND_TO_THREAD | SIGNAL_FLAG_QUEUING_REQUIRED); 55 if (error != B_OK) { 56 // translate B_BAD_THREAD_ID/B_BAD_TEAM_ID to ESRCH 57 if (error == B_BAD_THREAD_ID || error == B_BAD_TEAM_ID) 58 error = ESRCH; 59 } 60 61 RETURN_AND_SET_ERRNO(error); 62 } 63