xref: /haiku/src/system/libroot/posix/signal/sigqueue.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <signal.h>
8 
9 #include <errno.h>
10 
11 #include <syscall_utils.h>
12 
13 #include <errno_private.h>
14 #include <signal_defs.h>
15 #include <syscalls.h>
16 
17 
18 int
19 sigqueue(pid_t pid, int signal, const union sigval userValue)
20 {
21 	if (signal < 0)
22 		RETURN_AND_SET_ERRNO(EINVAL);
23 
24 	if (pid <= 0)
25 		RETURN_AND_SET_ERRNO(ESRCH);
26 
27 	status_t error = _kern_send_signal(pid, signal, &userValue,
28 		SIGNAL_FLAG_QUEUING_REQUIRED);
29 	if (error != B_OK) {
30 		// translate B_BAD_THREAD_ID/B_BAD_TEAM_ID to ESRCH
31 		if (error == B_BAD_THREAD_ID || error == B_BAD_TEAM_ID)
32 			error = ESRCH;
33 	}
34 
35 	RETURN_AND_SET_ERRNO(error);
36 }
37