thr_kill.c revision 285830
1272343Sngie/*
2272343Sngie * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
3272343Sngie * All rights reserved.
4272343Sngie *
5272343Sngie * Redistribution and use in source and binary forms, with or without
6272343Sngie * modification, are permitted provided that the following conditions
7272343Sngie * are met:
8272343Sngie * 1. Redistributions of source code must retain the above copyright
9272343Sngie *    notice, this list of conditions and the following disclaimer.
10272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
11272343Sngie *    notice, this list of conditions and the following disclaimer in the
12272343Sngie *    documentation and/or other materials provided with the distribution.
13272343Sngie * 3. Neither the name of the author nor the names of any co-contributors
14272343Sngie *    may be used to endorse or promote products derived from this software
15272343Sngie *    without specific prior written permission.
16272343Sngie *
17272343Sngie * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
18272343Sngie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19272343Sngie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20272343Sngie * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21272343Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23272343Sngie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24272343Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25272343Sngie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26272343Sngie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27272343Sngie * SUCH DAMAGE.
28272343Sngie *
29272343Sngie * $FreeBSD: releng/10.2/lib/libkse/thread/thr_kill.c 174689 2007-12-16 23:29:57Z deischen $
30272343Sngie */
31272343Sngie
32272343Sngie#include "namespace.h"
33272343Sngie#include <errno.h>
34272343Sngie#include <signal.h>
35272343Sngie#include <pthread.h>
36272343Sngie#include "un-namespace.h"
37272343Sngie#include "thr_private.h"
38272343Sngie
39276478Sngie__weak_reference(_pthread_kill, pthread_kill);
40276478Sngie
41276478Sngieint
42276478Sngie_pthread_kill(pthread_t pthread, int sig)
43272343Sngie{
44272343Sngie	struct pthread *curthread = _get_curthread();
45272343Sngie	int ret;
46272343Sngie
47272343Sngie	/* Check for invalid signal numbers: */
48272343Sngie	if (sig < 0 || sig > _SIG_MAXSIG)
49272343Sngie		/* Invalid signal: */
50272343Sngie		ret = EINVAL;
51272343Sngie	/*
52272343Sngie	 * Ensure the thread is in the list of active threads, and the
53272343Sngie	 * signal is valid (signal 0 specifies error checking only) and
54272343Sngie	 * not being ignored:
55272343Sngie	 */
56272343Sngie	else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
57272343Sngie	    == 0) {
58272343Sngie		if ((sig > 0) &&
59272343Sngie		    (_thread_sigact[sig - 1].sa_handler != SIG_IGN))
60272343Sngie			_thr_sig_send(pthread, sig);
61272343Sngie		_thr_ref_delete(curthread, pthread);
62272343Sngie	}
63272343Sngie
64272343Sngie	/* Return the completion status: */
65272343Sngie	return (ret);
66272343Sngie}
67272343Sngie