thr_kill.c revision 165967
1106266Sjulian/* 2106266Sjulian * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 3106266Sjulian * All rights reserved. 4106266Sjulian * 5106266Sjulian * Redistribution and use in source and binary forms, with or without 6106266Sjulian * modification, are permitted provided that the following conditions 7106266Sjulian * are met: 8106266Sjulian * 1. Redistributions of source code must retain the above copyright 9106266Sjulian * notice, this list of conditions and the following disclaimer. 10106266Sjulian * 2. Redistributions in binary form must reproduce the above copyright 11106266Sjulian * notice, this list of conditions and the following disclaimer in the 12106266Sjulian * documentation and/or other materials provided with the distribution. 13106266Sjulian * 3. Neither the name of the author nor the names of any co-contributors 14106266Sjulian * may be used to endorse or promote products derived from this software 15106266Sjulian * without specific prior written permission. 16106266Sjulian * 17106266Sjulian * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 18106266Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19106266Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20106266Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21106266Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22106266Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23106266Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24106266Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25106266Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26106266Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27106266Sjulian * SUCH DAMAGE. 28106266Sjulian * 29106266Sjulian * $FreeBSD: head/lib/libkse/thread/thr_kill.c 165967 2007-01-12 07:26:21Z imp $ 30106266Sjulian */ 31106266Sjulian#include <errno.h> 32106266Sjulian#include <signal.h> 33106266Sjulian#include <pthread.h> 34106266Sjulian#include "thr_private.h" 35106266Sjulian 36106266SjulianLT10_COMPAT_PRIVATE(_pthread_kill); 37106266SjulianLT10_COMPAT_DEFAULT(pthread_kill); 38106266Sjulian 39106266Sjulian__weak_reference(_pthread_kill, pthread_kill); 40106266Sjulian 41106266Sjulianint 42106266Sjulian_pthread_kill(pthread_t pthread, int sig) 43106266Sjulian{ 44106266Sjulian struct pthread *curthread = _get_curthread(); 45106266Sjulian int ret; 46106266Sjulian 47106266Sjulian /* Check for invalid signal numbers: */ 48106266Sjulian if (sig < 0 || sig > _SIG_MAXSIG) 49106266Sjulian /* Invalid signal: */ 50106266Sjulian ret = EINVAL; 51106266Sjulian /* 52106266Sjulian * Ensure the thread is in the list of active threads, and the 53106266Sjulian * signal is valid (signal 0 specifies error checking only) and 54106266Sjulian * not being ignored: 55106266Sjulian */ 56106266Sjulian else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) 57106266Sjulian == 0) { 58106266Sjulian if ((sig > 0) && 59106266Sjulian (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) 60106266Sjulian _thr_sig_send(pthread, sig); 61106266Sjulian _thr_ref_delete(curthread, pthread); 62106266Sjulian } 63106266Sjulian 64106266Sjulian /* Return the completion status: */ 65106266Sjulian return (ret); 66106266Sjulian} 67106266Sjulian