xref: /haiku/src/system/libroot/posix/signal/sigqueue.cpp (revision c80809a3ab0b0a2ce53ea861a2b00ace24ff452d)
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 <signal_defs.h>
14 #include <syscalls.h>
15 
16 
17 int
18 sigqueue(pid_t pid, int signal, const union sigval userValue)
19 {
20 	if (signal < 0)
21 		RETURN_AND_SET_ERRNO(EINVAL);
22 
23 	if (pid <= 0)
24 		RETURN_AND_SET_ERRNO(ESRCH);
25 
26 	status_t error = _kern_send_signal(pid, signal, &userValue,
27 		SIGNAL_FLAG_QUEUING_REQUIRED);
28 	if (error != B_OK) {
29 		// translate B_BAD_THREAD_ID/B_BAD_TEAM_ID to ESRCH
30 		if (error == B_BAD_THREAD_ID || error == B_BAD_TEAM_ID)
31 			error = ESRCH;
32 	}
33 
34 	RETURN_AND_SET_ERRNO(error);
35 }
36