124df6592SIngo Weinhold/*
224df6592SIngo Weinhold * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
324df6592SIngo Weinhold * Distributed under the terms of the MIT License.
424df6592SIngo Weinhold */
524df6592SIngo Weinhold
624df6592SIngo Weinhold
724df6592SIngo Weinhold#include <signal.h>
824df6592SIngo Weinhold
924df6592SIngo Weinhold#include <errno.h>
1024df6592SIngo Weinhold
1124df6592SIngo Weinhold#include <syscall_utils.h>
1224df6592SIngo Weinhold
13ae901935SOliver Tappe#include <errno_private.h>
1424df6592SIngo Weinhold#include <signal_defs.h>
1524df6592SIngo Weinhold#include <syscalls.h>
1624df6592SIngo Weinhold
1724df6592SIngo Weinhold
1824df6592SIngo Weinholdint
1924df6592SIngo Weinholdsigqueue(pid_t pid, int signal, const union sigval userValue)
2024df6592SIngo Weinhold{
2124df6592SIngo Weinhold	if (signal < 0)
2224df6592SIngo Weinhold		RETURN_AND_SET_ERRNO(EINVAL);
2324df6592SIngo Weinhold
2424df6592SIngo Weinhold	if (pid <= 0)
2524df6592SIngo Weinhold		RETURN_AND_SET_ERRNO(ESRCH);
2624df6592SIngo Weinhold
2724df6592SIngo Weinhold	status_t error = _kern_send_signal(pid, signal, &userValue,
2824df6592SIngo Weinhold		SIGNAL_FLAG_QUEUING_REQUIRED);
2924df6592SIngo Weinhold	if (error != B_OK) {
3024df6592SIngo Weinhold		// translate B_BAD_THREAD_ID/B_BAD_TEAM_ID to ESRCH
3124df6592SIngo Weinhold		if (error == B_BAD_THREAD_ID || error == B_BAD_TEAM_ID)
3224df6592SIngo Weinhold			error = ESRCH;
3324df6592SIngo Weinhold	}
3424df6592SIngo Weinhold
3524df6592SIngo Weinhold	RETURN_AND_SET_ERRNO(error);
3624df6592SIngo Weinhold}