thr_kill.c revision 103388
10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 30Sstevel@tonic-gate * All rights reserved. 40Sstevel@tonic-gate * 51916Smb158278 * Redistribution and use in source and binary forms, with or without 61916Smb158278 * modification, are permitted provided that the following conditions 70Sstevel@tonic-gate * are met: 80Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 90Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 100Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 110Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 120Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 130Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 140Sstevel@tonic-gate * must display the following acknowledgement: 150Sstevel@tonic-gate * This product includes software developed by John Birrell. 160Sstevel@tonic-gate * 4. Neither the name of the author nor the names of any co-contributors 170Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 180Sstevel@tonic-gate * without specific prior written permission. 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 210Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221916Smb158278 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 240Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300Sstevel@tonic-gate * SUCH DAMAGE. 310Sstevel@tonic-gate * 320Sstevel@tonic-gate * $FreeBSD: head/lib/libkse/thread/thr_kill.c 103388 2002-09-16 08:45:36Z mini $ 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate#include <errno.h> 350Sstevel@tonic-gate#include <signal.h> 360Sstevel@tonic-gate#include <pthread.h> 370Sstevel@tonic-gate#include "thr_private.h" 380Sstevel@tonic-gate 390Sstevel@tonic-gate__weak_reference(_pthread_kill, pthread_kill); 400Sstevel@tonic-gate 410Sstevel@tonic-gateint 420Sstevel@tonic-gate_pthread_kill(pthread_t pthread, int sig) 430Sstevel@tonic-gate{ 440Sstevel@tonic-gate int ret; 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* Check for invalid signal numbers: */ 470Sstevel@tonic-gate if (sig < 0 || sig >= NSIG) 480Sstevel@tonic-gate /* Invalid signal: */ 490Sstevel@tonic-gate ret = EINVAL; 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * Ensure the thread is in the list of active threads, and the 520Sstevel@tonic-gate * signal is valid (signal 0 specifies error checking only) and 530Sstevel@tonic-gate * not being ignored: 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate else if (((ret = _find_thread(pthread)) == 0) && (sig > 0) && 560Sstevel@tonic-gate (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) { 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Defer signals to protect the scheduling queues from 590Sstevel@tonic-gate * access by the signal handler: 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate _thread_kern_sig_defer(); 620Sstevel@tonic-gate 630Sstevel@tonic-gate _thread_sig_send(pthread, sig); 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Undefer and handle pending signals, yielding if 670Sstevel@tonic-gate * necessary: 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate _thread_kern_sig_undefer(); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* Return the completion status: */ 730Sstevel@tonic-gate return (ret); 740Sstevel@tonic-gate} 750Sstevel@tonic-gate