thr_kill.c revision 256281
1178476Sjb/* 2178476Sjb * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 3178476Sjb * All rights reserved. 4178476Sjb * 5178476Sjb * Redistribution and use in source and binary forms, with or without 6178476Sjb * modification, are permitted provided that the following conditions 7178476Sjb * are met: 8178476Sjb * 1. Redistributions of source code must retain the above copyright 9178476Sjb * notice, this list of conditions and the following disclaimer. 10178476Sjb * 2. Redistributions in binary form must reproduce the above copyright 11178476Sjb * notice, this list of conditions and the following disclaimer in the 12178476Sjb * documentation and/or other materials provided with the distribution. 13178476Sjb * 3. Neither the name of the author nor the names of any co-contributors 14178476Sjb * may be used to endorse or promote products derived from this software 15178476Sjb * without specific prior written permission. 16178476Sjb * 17178476Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 18178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20178476Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21178476Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22178476Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23178476Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24178476Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25178476Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26178476Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27178476Sjb * SUCH DAMAGE. 28178476Sjb * 29178476Sjb * $FreeBSD: stable/10/lib/libkse/thread/thr_kill.c 174689 2007-12-16 23:29:57Z deischen $ 30178476Sjb */ 31178476Sjb 32178476Sjb#include "namespace.h" 33178476Sjb#include <errno.h> 34178476Sjb#include <signal.h> 35178476Sjb#include <pthread.h> 36178476Sjb#include "un-namespace.h" 37178476Sjb#include "thr_private.h" 38178476Sjb 39178476Sjb__weak_reference(_pthread_kill, pthread_kill); 40178476Sjb 41178476Sjbint 42178476Sjb_pthread_kill(pthread_t pthread, int sig) 43178476Sjb{ 44178476Sjb struct pthread *curthread = _get_curthread(); 45178476Sjb int ret; 46178476Sjb 47178476Sjb /* Check for invalid signal numbers: */ 48178476Sjb if (sig < 0 || sig > _SIG_MAXSIG) 49178476Sjb /* Invalid signal: */ 50178476Sjb ret = EINVAL; 51178476Sjb /* 52178476Sjb * Ensure the thread is in the list of active threads, and the 53178476Sjb * signal is valid (signal 0 specifies error checking only) and 54178476Sjb * not being ignored: 55178476Sjb */ 56178476Sjb else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) 57178476Sjb == 0) { 58178476Sjb if ((sig > 0) && 59178476Sjb (_thread_sigact[sig - 1].sa_handler != SIG_IGN)) 60178476Sjb _thr_sig_send(pthread, sig); 61178476Sjb _thr_ref_delete(curthread, pthread); 62178476Sjb } 63178476Sjb 64178534Sjb /* Return the completion status: */ 65178534Sjb return (ret); 66178534Sjb} 67178534Sjb