Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Jun 2010 20:41:52 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r209592 - in head/sys: compat/linux kern sys
Message-ID:  <201006292041.o5TKfqbv031066@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Jun 29 20:41:52 2010
New Revision: 209592
URL: http://svn.freebsd.org/changeset/base/209592

Log:
  Tweak the in-kernel API for sending signals to threads:
  - Rename tdsignal() to tdsendsignal() and make it private to kern_sig.c.
  - Add tdsignal() and tdksignal() routines that mirror psignal() and
    pksignal() except that they accept a thread as an argument instead of
    a process.  They send a signal to a specific thread rather than to an
    individual process.
  
  Reviewed by:	kib

Modified:
  head/sys/compat/linux/linux_signal.c
  head/sys/kern/kern_exec.c
  head/sys/kern/kern_exit.c
  head/sys/kern/kern_sig.c
  head/sys/kern/kern_thr.c
  head/sys/sys/signalvar.h

Modified: head/sys/compat/linux/linux_signal.c
==============================================================================
--- head/sys/compat/linux/linux_signal.c	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/compat/linux/linux_signal.c	Tue Jun 29 20:41:52 2010	(r209592)
@@ -501,7 +501,7 @@ linux_rt_sigtimedwait(struct thread *td,
 	/* Repost if we got an error. */
 	if (error && info.ksi_signo) {
 		PROC_LOCK(td->td_proc);
-		tdsignal(td->td_proc, td, info.ksi_signo, &info);
+		tdksignal(td, info.ksi_signo, &info);
 		PROC_UNLOCK(td->td_proc);
 	} else
 		td->td_retval[0] = info.ksi_signo; 
@@ -587,7 +587,7 @@ linux_do_tkill(struct thread *td, l_int 
 	ksi.ksi_pid = proc->p_pid;
 	ksi.ksi_uid = proc->p_ucred->cr_ruid;
 
-	error = tdsignal(p, NULL, ksi.ksi_signo, &ksi);
+	error = pksignal(p, ksi.ksi_signo, &ksi);
 
 out:
 	PROC_UNLOCK(p);

Modified: head/sys/kern/kern_exec.c
==============================================================================
--- head/sys/kern/kern_exec.c	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/kern/kern_exec.c	Tue Jun 29 20:41:52 2010	(r209592)
@@ -755,13 +755,13 @@ interpret:
 	/*
 	 * If tracing the process, trap to debugger so breakpoints
 	 * can be set before the program executes.
-	 * Use tdsignal to deliver signal to current thread, use
+	 * Use tdsignal to deliver signal to current thread, using
 	 * psignal may cause the signal to be delivered to wrong thread
 	 * because that thread will exit, remember we are going to enter
 	 * single thread mode.
 	 */
 	if (p->p_flag & P_TRACED)
-		tdsignal(p, td, SIGTRAP, NULL);
+		tdsignal(td, SIGTRAP);
 
 	/* clear "fork but no exec" flag, as we _are_ execing */
 	p->p_acflag &= ~AFORK;

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/kern/kern_exit.c	Tue Jun 29 20:41:52 2010	(r209592)
@@ -732,7 +732,7 @@ proc_reap(struct thread *td, struct proc
 		p->p_oppid = 0;
 		proc_reparent(p, t);
 		PROC_UNLOCK(p);
-		tdsignal(t, NULL, SIGCHLD, p->p_ksi);
+		pksignal(t, SIGCHLD, p->p_ksi);
 		wakeup(t);
 		cv_broadcast(&p->p_pwait);
 		PROC_UNLOCK(t);

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/kern/kern_sig.c	Tue Jun 29 20:41:52 2010	(r209592)
@@ -107,6 +107,8 @@ static int	killpg1(struct thread *td, in
 		    ksiginfo_t *ksi);
 static int	issignal(struct thread *td, int stop_allowed);
 static int	sigprop(int sig);
+static int	tdsendsignal(struct proc *p, struct thread *td, int sig,
+		    ksiginfo_t *ksi);
 static void	tdsigwakeup(struct thread *, int, sig_t, int);
 static void	sig_suspend_threads(struct thread *, struct proc *, int);
 static int	filt_sigattach(struct knote *kn);
@@ -1797,7 +1799,7 @@ sigqueue(struct thread *td, struct sigqu
 		ksi.ksi_pid = td->td_proc->p_pid;
 		ksi.ksi_uid = td->td_ucred->cr_ruid;
 		ksi.ksi_value.sival_ptr = uap->value;
-		error = tdsignal(p, NULL, ksi.ksi_signo, &ksi);
+		error = pksignal(p, ksi.ksi_signo, &ksi);
 	}
 	PROC_UNLOCK(p);
 	return (error);
@@ -1907,7 +1909,7 @@ trapsignal(struct thread *td, ksiginfo_t
 		mtx_unlock(&ps->ps_mtx);
 		p->p_code = code;	/* XXX for core dump/debugger */
 		p->p_sig = sig;		/* XXX to verify code */
-		tdsignal(p, td, sig, ksi);
+		tdsendsignal(p, td, sig, ksi);
 	}
 	PROC_UNLOCK(p);
 }
@@ -1962,14 +1964,14 @@ psignal(struct proc *p, int sig)
 	ksiginfo_init(&ksi);
 	ksi.ksi_signo = sig;
 	ksi.ksi_code = SI_KERNEL;
-	(void) tdsignal(p, NULL, sig, &ksi);
+	(void) tdsendsignal(p, NULL, sig, &ksi);
 }
 
-void
+int
 pksignal(struct proc *p, int sig, ksiginfo_t *ksi)
 {
 
-	(void) tdsignal(p, NULL, sig, ksi);
+	return (tdsendsignal(p, NULL, sig, ksi));
 }
 
 int
@@ -1992,11 +1994,29 @@ psignal_event(struct proc *p, struct sig
 		if (td == NULL)
 			return (ESRCH);
 	}
-	return (tdsignal(p, td, ksi->ksi_signo, ksi));
+	return (tdsendsignal(p, td, ksi->ksi_signo, ksi));
 }
 
-int
-tdsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
+void
+tdsignal(struct thread *td, int sig)
+{
+	ksiginfo_t ksi;
+
+	ksiginfo_init(&ksi);
+	ksi.ksi_signo = sig;
+	ksi.ksi_code = SI_KERNEL;
+	(void) tdsendsignal(td->td_proc, td, sig, &ksi);
+}
+
+void
+tdksignal(struct thread *td, int sig, ksiginfo_t *ksi)
+{
+
+	(void) tdsendsignal(td->td_proc, td, sig, ksi);
+}
+
+static int
+tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
 {
 	sig_t action;
 	sigqueue_t *sigqueue;
@@ -2882,7 +2902,7 @@ sigparent(struct proc *p, int reason, in
 		if (KSI_ONQ(p->p_ksi))
 			return;
 	}
-	tdsignal(p->p_pptr, NULL, SIGCHLD, p->p_ksi);
+	pksignal(p->p_pptr, SIGCHLD, p->p_ksi);
 }
 
 static void

Modified: head/sys/kern/kern_thr.c
==============================================================================
--- head/sys/kern/kern_thr.c	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/kern/kern_thr.c	Tue Jun 29 20:41:52 2010	(r209592)
@@ -326,7 +326,7 @@ thr_kill(struct thread *td, struct thr_k
 					error = 0;
 					if (uap->sig == 0)
 						break;
-					tdsignal(p, ttd, uap->sig, &ksi);
+					tdksignal(ttd, uap->sig, &ksi);
 				}
 			}
 		}
@@ -342,7 +342,7 @@ thr_kill(struct thread *td, struct thr_k
 		else if (!_SIG_VALID(uap->sig))
 			error = EINVAL;
 		else
-			tdsignal(p, ttd, uap->sig, &ksi);
+			tdksignal(ttd, uap->sig, &ksi);
 	}
 	PROC_UNLOCK(p);
 	return (error);
@@ -384,8 +384,7 @@ thr_kill2(struct thread *td, struct thr_
 						error = 0;
 						if (uap->sig == 0)
 							break;
-						tdsignal(p, ttd, uap->sig,
-						    &ksi);
+						tdksignal(ttd, uap->sig, &ksi);
 					}
 				}
 			}
@@ -401,7 +400,7 @@ thr_kill2(struct thread *td, struct thr_
 			else if (!_SIG_VALID(uap->sig))
 				error = EINVAL;
 			else
-				tdsignal(p, ttd, uap->sig, &ksi);
+				tdksignal(ttd, uap->sig, &ksi);
 		}
 	}
 	PROC_UNLOCK(p);

Modified: head/sys/sys/signalvar.h
==============================================================================
--- head/sys/sys/signalvar.h	Tue Jun 29 19:07:44 2010	(r209591)
+++ head/sys/sys/signalvar.h	Tue Jun 29 20:41:52 2010	(r209592)
@@ -330,7 +330,7 @@ int	cursig(struct thread *td, int stop_a
 void	execsigs(struct proc *p);
 void	gsignal(int pgid, int sig, ksiginfo_t *ksi);
 void	killproc(struct proc *p, char *why);
-void	pksignal(struct proc *p, int sig, ksiginfo_t *ksi);
+int	pksignal(struct proc *p, int sig, ksiginfo_t *ksi);
 void	pgsigio(struct sigio **, int signum, int checkctty);
 void	pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi);
 int	postsig(int sig);
@@ -346,8 +346,8 @@ int	sig_ffs(sigset_t *set);
 void	siginit(struct proc *p);
 void	signotify(struct thread *td);
 void	tdsigcleanup(struct thread *td);
-int	tdsignal(struct proc *p, struct thread *td, int sig,
-	    ksiginfo_t *ksi);
+void	tdsignal(struct thread *td, int sig);
+void	tdksignal(struct thread *td, int sig, ksiginfo_t *ksi);
 void	trapsignal(struct thread *td, ksiginfo_t *);
 int	ptracestop(struct thread *td, int sig);
 ksiginfo_t * ksiginfo_alloc(int);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006292041.o5TKfqbv031066>