kern_sig.c (90670) | kern_sig.c (91140) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94 |
39 * $FreeBSD: head/sys/kern/kern_sig.c 90670 2002-02-15 03:54:01Z bde $ | 39 * $FreeBSD: head/sys/kern/kern_sig.c 91140 2002-02-23 11:12:57Z tanimura $ |
40 */ 41 42#include "opt_compat.h" 43#include "opt_ktrace.h" 44 45#include <sys/param.h> 46#include <sys/kernel.h> 47#include <sys/sysproto.h> --- 948 unchanged lines hidden (view full) --- 996 nfound++; 997 if (sig) 998 psignal(p, sig); 999 } 1000 PROC_UNLOCK(p); 1001 } 1002 sx_sunlock(&allproc_lock); 1003 } else { | 40 */ 41 42#include "opt_compat.h" 43#include "opt_ktrace.h" 44 45#include <sys/param.h> 46#include <sys/kernel.h> 47#include <sys/sysproto.h> --- 948 unchanged lines hidden (view full) --- 996 nfound++; 997 if (sig) 998 psignal(p, sig); 999 } 1000 PROC_UNLOCK(p); 1001 } 1002 sx_sunlock(&allproc_lock); 1003 } else { |
1004 if (pgid == 0) | 1004 PGRPSESS_SLOCK(); 1005 if (pgid == 0) { |
1005 /* 1006 * zero pgid means send to my process group. 1007 */ 1008 pgrp = cp->p_pgrp; | 1006 /* 1007 * zero pgid means send to my process group. 1008 */ 1009 pgrp = cp->p_pgrp; |
1009 else { | 1010 PGRP_LOCK(pgrp); 1011 } else { |
1010 pgrp = pgfind(pgid); | 1012 pgrp = pgfind(pgid); |
1011 if (pgrp == NULL) | 1013 if (pgrp == NULL) { 1014 PGRPSESS_SUNLOCK(); |
1012 return (ESRCH); | 1015 return (ESRCH); |
1016 } |
|
1013 } | 1017 } |
1018 PGRPSESS_SUNLOCK(); |
|
1014 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { 1015 PROC_LOCK(p); 1016 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM) { 1017 PROC_UNLOCK(p); 1018 continue; 1019 } 1020 mtx_lock_spin(&sched_lock); 1021 if (p->p_stat == SZOMB) { --- 4 unchanged lines hidden (view full) --- 1026 mtx_unlock_spin(&sched_lock); 1027 if (p_cansignal(cp, p, sig) == 0) { 1028 nfound++; 1029 if (sig) 1030 psignal(p, sig); 1031 } 1032 PROC_UNLOCK(p); 1033 } | 1019 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { 1020 PROC_LOCK(p); 1021 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM) { 1022 PROC_UNLOCK(p); 1023 continue; 1024 } 1025 mtx_lock_spin(&sched_lock); 1026 if (p->p_stat == SZOMB) { --- 4 unchanged lines hidden (view full) --- 1031 mtx_unlock_spin(&sched_lock); 1032 if (p_cansignal(cp, p, sig) == 0) { 1033 nfound++; 1034 if (sig) 1035 psignal(p, sig); 1036 } 1037 PROC_UNLOCK(p); 1038 } |
1039 PGRP_UNLOCK(pgrp); |
|
1034 } 1035 return (nfound ? 0 : ESRCH); 1036} 1037 1038#ifndef _SYS_SYSPROTO_H_ 1039struct kill_args { 1040 int pid; 1041 int signum; --- 77 unchanged lines hidden (view full) --- 1119 * Send a signal to a process group. 1120 */ 1121void 1122gsignal(pgid, sig) 1123 int pgid, sig; 1124{ 1125 struct pgrp *pgrp; 1126 | 1040 } 1041 return (nfound ? 0 : ESRCH); 1042} 1043 1044#ifndef _SYS_SYSPROTO_H_ 1045struct kill_args { 1046 int pid; 1047 int signum; --- 77 unchanged lines hidden (view full) --- 1125 * Send a signal to a process group. 1126 */ 1127void 1128gsignal(pgid, sig) 1129 int pgid, sig; 1130{ 1131 struct pgrp *pgrp; 1132 |
1127 if (pgid && (pgrp = pgfind(pgid))) 1128 pgsignal(pgrp, sig, 0); | 1133 if (pgid != 0) { 1134 PGRPSESS_SLOCK(); 1135 pgrp = pgfind(pgid); 1136 PGRPSESS_SUNLOCK(); 1137 if (pgrp != NULL) { 1138 pgsignal(pgrp, sig, 0); 1139 PGRP_UNLOCK(pgrp); 1140 } 1141 } |
1129} 1130 1131/* 1132 * Send a signal to a process group. If checktty is 1, 1133 * limit to members which have a controlling terminal. 1134 */ 1135void 1136pgsignal(pgrp, sig, checkctty) 1137 struct pgrp *pgrp; 1138 int sig, checkctty; 1139{ 1140 register struct proc *p; 1141 1142 if (pgrp) { | 1142} 1143 1144/* 1145 * Send a signal to a process group. If checktty is 1, 1146 * limit to members which have a controlling terminal. 1147 */ 1148void 1149pgsignal(pgrp, sig, checkctty) 1150 struct pgrp *pgrp; 1151 int sig, checkctty; 1152{ 1153 register struct proc *p; 1154 1155 if (pgrp) { |
1156 PGRP_LOCK_ASSERT(pgrp, MA_OWNED); |
|
1143 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { 1144 PROC_LOCK(p); 1145 if (checkctty == 0 || p->p_flag & P_CONTROLT) 1146 psignal(p, sig); 1147 PROC_UNLOCK(p); 1148 } 1149 } 1150} --- 195 unchanged lines hidden (view full) --- 1346 /* 1347 * If a child holding parent blocked, 1348 * stopping could cause deadlock. 1349 */ 1350 if (p->p_flag & P_PPWAIT) 1351 goto out; 1352 SIGDELSET(p->p_siglist, sig); 1353 p->p_xstat = sig; | 1157 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { 1158 PROC_LOCK(p); 1159 if (checkctty == 0 || p->p_flag & P_CONTROLT) 1160 psignal(p, sig); 1161 PROC_UNLOCK(p); 1162 } 1163 } 1164} --- 195 unchanged lines hidden (view full) --- 1360 /* 1361 * If a child holding parent blocked, 1362 * stopping could cause deadlock. 1363 */ 1364 if (p->p_flag & P_PPWAIT) 1365 goto out; 1366 SIGDELSET(p->p_siglist, sig); 1367 p->p_xstat = sig; |
1354 if ((p->p_pptr->p_procsig->ps_flag & PS_NOCLDSTOP) == 0) { 1355 PROC_LOCK(p->p_pptr); | 1368 PROC_LOCK(p->p_pptr); 1369 if ((p->p_pptr->p_procsig->ps_flag & PS_NOCLDSTOP) == 0) |
1356 psignal(p->p_pptr, SIGCHLD); | 1370 psignal(p->p_pptr, SIGCHLD); |
1357 PROC_UNLOCK(p->p_pptr); 1358 } | 1371 PROC_UNLOCK(p->p_pptr); |
1359 mtx_lock_spin(&sched_lock); 1360 stop(p); 1361 mtx_unlock_spin(&sched_lock); 1362 goto out; 1363 } else 1364 goto runfast; 1365 /* NOTREACHED */ 1366 --- 257 unchanged lines hidden (view full) --- 1624 * with default action, stop here, 1625 * then clear the signal. However, 1626 * if process is member of an orphaned 1627 * process group, ignore tty stop signals. 1628 */ 1629 if (prop & SA_STOP) { 1630 if (p->p_flag & P_TRACED || 1631 (p->p_pgrp->pg_jobc == 0 && | 1372 mtx_lock_spin(&sched_lock); 1373 stop(p); 1374 mtx_unlock_spin(&sched_lock); 1375 goto out; 1376 } else 1377 goto runfast; 1378 /* NOTREACHED */ 1379 --- 257 unchanged lines hidden (view full) --- 1637 * with default action, stop here, 1638 * then clear the signal. However, 1639 * if process is member of an orphaned 1640 * process group, ignore tty stop signals. 1641 */ 1642 if (prop & SA_STOP) { 1643 if (p->p_flag & P_TRACED || 1644 (p->p_pgrp->pg_jobc == 0 && |
1632 prop & SA_TTYSTOP)) | 1645 prop & SA_TTYSTOP)) |
1633 break; /* == ignore */ 1634 p->p_xstat = sig; | 1646 break; /* == ignore */ 1647 p->p_xstat = sig; |
1635 if ((p->p_pptr->p_procsig->ps_flag & PS_NOCLDSTOP) == 0) { 1636 PROC_LOCK(p->p_pptr); | 1648 PROC_LOCK(p->p_pptr); 1649 if ((p->p_pptr->p_procsig->ps_flag & PS_NOCLDSTOP) == 0) |
1637 psignal(p->p_pptr, SIGCHLD); | 1650 psignal(p->p_pptr, SIGCHLD); |
1638 PROC_UNLOCK(p->p_pptr); 1639 } | 1651 PROC_UNLOCK(p->p_pptr); |
1640 mtx_lock_spin(&sched_lock); 1641 stop(p); 1642 PROC_UNLOCK(p); 1643 DROP_GIANT(); 1644 p->p_stats->p_ru.ru_nivcsw++; 1645 mi_switch(); 1646 mtx_unlock_spin(&sched_lock); 1647 PICKUP_GIANT(); --- 421 unchanged lines hidden (view full) --- 2069 */ 2070void 2071pgsigio(sigio, sig, checkctty) 2072 struct sigio *sigio; 2073 int sig, checkctty; 2074{ 2075 if (sigio == NULL) 2076 return; | 1652 mtx_lock_spin(&sched_lock); 1653 stop(p); 1654 PROC_UNLOCK(p); 1655 DROP_GIANT(); 1656 p->p_stats->p_ru.ru_nivcsw++; 1657 mi_switch(); 1658 mtx_unlock_spin(&sched_lock); 1659 PICKUP_GIANT(); --- 421 unchanged lines hidden (view full) --- 2081 */ 2082void 2083pgsigio(sigio, sig, checkctty) 2084 struct sigio *sigio; 2085 int sig, checkctty; 2086{ 2087 if (sigio == NULL) 2088 return; |
2077 | 2089 |
2078 if (sigio->sio_pgid > 0) { 2079 PROC_LOCK(sigio->sio_proc); 2080 if (CANSIGIO(sigio->sio_ucred, sigio->sio_proc->p_ucred)) 2081 psignal(sigio->sio_proc, sig); 2082 PROC_UNLOCK(sigio->sio_proc); 2083 } else if (sigio->sio_pgid < 0) { 2084 struct proc *p; 2085 | 2090 if (sigio->sio_pgid > 0) { 2091 PROC_LOCK(sigio->sio_proc); 2092 if (CANSIGIO(sigio->sio_ucred, sigio->sio_proc->p_ucred)) 2093 psignal(sigio->sio_proc, sig); 2094 PROC_UNLOCK(sigio->sio_proc); 2095 } else if (sigio->sio_pgid < 0) { 2096 struct proc *p; 2097 |
2098 PGRP_LOCK(sigio->sio_pgrp); |
|
2086 LIST_FOREACH(p, &sigio->sio_pgrp->pg_members, p_pglist) { 2087 PROC_LOCK(p); 2088 if (CANSIGIO(sigio->sio_ucred, p->p_ucred) && 2089 (checkctty == 0 || (p->p_flag & P_CONTROLT))) 2090 psignal(p, sig); 2091 PROC_UNLOCK(p); 2092 } | 2099 LIST_FOREACH(p, &sigio->sio_pgrp->pg_members, p_pglist) { 2100 PROC_LOCK(p); 2101 if (CANSIGIO(sigio->sio_ucred, p->p_ucred) && 2102 (checkctty == 0 || (p->p_flag & P_CONTROLT))) 2103 psignal(p, sig); 2104 PROC_UNLOCK(p); 2105 } |
2106 PGRP_UNLOCK(sigio->sio_pgrp); |
|
2093 } 2094} 2095 2096static int 2097filt_sigattach(struct knote *kn) 2098{ 2099 struct proc *p = curproc; 2100 --- 38 unchanged lines hidden --- | 2107 } 2108} 2109 2110static int 2111filt_sigattach(struct knote *kn) 2112{ 2113 struct proc *p = curproc; 2114 --- 38 unchanged lines hidden --- |