4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/vnode.h>
39 #include <sys/errno.h>
41 #include <sys/mount.h>
43 #include <sys/signal.h>
44 #include <sys/siginfo.h>
45 #include <sys/ucontext.h>
46 #include <sys/prsystm.h>
47 #include <sys/session.h>
48 #include <sys/stream.h>
49 #include <sys/strsubr.h>
50 #include <sys/debug.h>
53 * Return 1 if process pointed to by 'cp' has a parent that would
54 * prevent its process group from being orphaned, 0 otherwise
63 ASSERT(MUTEX_HELD(&pidlock
));
65 if ((pp
= cp
->p_parent
) != NULL
&&
66 pp
->p_pgidp
!= cp
->p_pgidp
&&
67 pp
->p_sessp
== cp
->p_sessp
)
73 * Send the specified signal to all processes whose process group ID is
79 register struct pid
*pidp
;
84 mutex_enter(&pidlock
);
85 for (prp
= pidp
->pid_pglink
; prp
; prp
= prp
->p_pglink
) {
86 mutex_enter(&prp
->p_lock
);
87 sigtoproc(prp
, NULL
, sig
);
88 mutex_exit(&prp
->p_lock
);
94 * similiar to pgsignal in function except that pidlock mutex is assumed
95 * to be held by the caller.
99 register struct pid
*pidp
;
102 register proc_t
*prp
;
104 ASSERT(MUTEX_HELD(&pidlock
));
106 for (prp
= pidp
->pid_pglink
; prp
; prp
= prp
->p_pglink
) {
107 mutex_enter(&prp
->p_lock
);
108 sigtoproc(prp
, NULL
, sig
);
109 mutex_exit(&prp
->p_lock
);
114 * Add a process to a process group
120 register struct pid
*pgp
;
122 ASSERT(MUTEX_HELD(&pidlock
));
126 if (pgp
->pid_pglink
== NULL
) {
127 ASSERT(pgp
->pid_pgtail
== NULL
);
133 ASSERT(pgp
->pid_pgtail
!= NULL
);
136 p
->p_pglink
= pgp
->pid_pglink
;
137 pgp
->pid_pglink
->p_ppglink
= p
;
140 p
->p_ppglink
= pgp
->pid_pgtail
;
142 pgp
->pid_pgtail
->p_pglink
= p
;
147 if (pgp
->pid_pglink
== pgp
->pid_pgtail
) {
150 pgp
->pid_pgorphaned
= 0;
152 pgp
->pid_pgorphaned
= 1;
153 } else if (pgp
->pid_pgorphaned
&& pglinked(p
))
154 pgp
->pid_pgorphaned
= 0;
162 register struct pid
*pgp
;
164 ASSERT(MUTEX_HELD(&pidlock
));
168 if (pgp
->pid_pglink
== prp
) {
169 ASSERT(prp
->p_ppglink
== NULL
); /* must be at the front */
170 pgp
->pid_pglink
= prp
->p_pglink
;
172 if (prp
->p_ppglink
) {
173 prp
->p_ppglink
->p_pglink
= prp
->p_pglink
;
176 prp
->p_pglink
->p_ppglink
= prp
->p_ppglink
;
178 if (pgp
->pid_pgtail
== prp
) {
179 pgp
->pid_pgtail
= prp
->p_ppglink
;
183 prp
->p_pglink
= NULL
;
184 prp
->p_ppglink
= NULL
;
186 if ((p
= pgp
->pid_pglink
) == NULL
) {
188 } else if (pgp
->pid_pgorphaned
== 0) {
193 } while ((p
= p
->p_pglink
) != NULL
);
194 pgp
->pid_pgorphaned
= 1;
199 * process 'pp' is exiting - check to see if this will
200 * orphan its children's process groups
210 register struct pid
*pgp
;
212 ASSERT(MUTEX_HELD(&pidlock
));
214 for (cp
= pp
->p_child
; cp
; cp
= cp
->p_sibling
) {
215 if ((pgp
= cp
->p_pgidp
)->pid_pgorphaned
)
218 mp
= pgp
->pid_pglink
;
221 if (mp
!= pp
&& mp
->p_parent
!= pp
&& pglinked(mp
))
223 if (!stopped
&& mp
!= curproc
) {
224 mutex_enter(&mp
->p_lock
);
225 stopped
= jobstopped(mp
);
226 mutex_exit(&mp
->p_lock
);
228 if ((mp
= mp
->p_pglink
) == NULL
) {
229 pgp
->pid_pgorphaned
= 1;
231 sigtopg(pgp
, SIGHUP
);
232 sigtopg(pgp
, SIGCONT
);
241 * Return 1 if pgid is the process group ID of an existing process group
242 * that has members not the process group leader in it.
244 * Otherwise, return 0.
251 register proc_t
*prp
;
253 ASSERT(MUTEX_HELD(&pidlock
));
255 for (prp
= pgfind(pgid
); prp
; prp
= prp
->p_pglink
)
256 if (prp
->p_pid
!= pgid
) {