fownsignal: pre-check for zero pgid, avoids locking of proc_lock.

This commit is contained in:
rmind 2009-03-29 04:40:01 +00:00
parent 49be05cbf6
commit 6b0e9f0301

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_descrip.c,v 1.188 2009/03/11 06:05:29 mrg Exp $ */
/* $NetBSD: kern_descrip.c,v 1.189 2009/03/29 04:40:01 rmind Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.188 2009/03/11 06:05:29 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.189 2009/03/29 04:40:01 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1635,22 +1635,36 @@ fgetown(pid_t pgid, u_long cmd, void *data)
void
fownsignal(pid_t pgid, int signo, int code, int band, void *fdescdata)
{
struct proc *p1;
struct pgrp *pgrp;
ksiginfo_t ksi;
KASSERT(!cpu_intr_p());
if (pgid == 0) {
return;
}
KSI_INIT(&ksi);
ksi.ksi_signo = signo;
ksi.ksi_code = code;
ksi.ksi_band = band;
mutex_enter(proc_lock);
if (pgid > 0 && (p1 = p_find(pgid, PFIND_LOCKED)))
kpsignal(p1, &ksi, fdescdata);
else if (pgid < 0 && (pgrp = pg_find(-pgid, PFIND_LOCKED)))
kpgsignal(pgrp, &ksi, fdescdata, 0);
if (pgid > 0) {
struct proc *p1;
p1 = p_find(pgid, PFIND_LOCKED);
if (p1 != NULL) {
kpsignal(p1, &ksi, fdescdata);
}
} else {
struct pgrp *pgrp;
KASSERT(pgid < 0);
pgrp = pg_find(-pgid, PFIND_LOCKED);
if (pgrp != NULL) {
kpgsignal(pgrp, &ksi, fdescdata, 0);
}
}
mutex_exit(proc_lock);
}