kern_fork.c (14362) | kern_fork.c (14529) |
---|---|
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_fork.c 8.6 (Berkeley) 4/8/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_fork.c 8.6 (Berkeley) 4/8/94 |
39 * $Id: kern_fork.c,v 1.17 1996/02/23 18:49:17 peter Exp $ | 39 * $Id: kern_fork.c,v 1.18 1996/03/03 19:48:45 dyson Exp $ |
40 */ 41 42#include "opt_ktrace.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/filedesc.h> --- 142 unchanged lines hidden (view full) --- 190 int doingzomb = 0; 191 192 pidchecked = PID_MAX; 193 /* 194 * Scan the active and zombie procs to check whether this pid 195 * is in use. Remember the lowest pid that's greater 196 * than nextpid, so we can avoid checking for a while. 197 */ | 40 */ 41 42#include "opt_ktrace.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/sysproto.h> 47#include <sys/filedesc.h> --- 142 unchanged lines hidden (view full) --- 190 int doingzomb = 0; 191 192 pidchecked = PID_MAX; 193 /* 194 * Scan the active and zombie procs to check whether this pid 195 * is in use. Remember the lowest pid that's greater 196 * than nextpid, so we can avoid checking for a while. 197 */ |
198 p2 = (struct proc *)allproc; | 198 p2 = allproc.lh_first; |
199again: | 199again: |
200 for (; p2 != NULL; p2 = p2->p_next) { | 200 for (; p2 != 0; p2 = p2->p_list.le_next) { |
201 while (p2->p_pid == nextpid || 202 p2->p_pgrp->pg_id == nextpid) { 203 nextpid++; 204 if (nextpid >= pidchecked) 205 goto retry; 206 } 207 if (p2->p_pid > nextpid && pidchecked > p2->p_pid) 208 pidchecked = p2->p_pid; 209 if (p2->p_pgrp->pg_id > nextpid && 210 pidchecked > p2->p_pgrp->pg_id) 211 pidchecked = p2->p_pgrp->pg_id; 212 } 213 if (!doingzomb) { 214 doingzomb = 1; | 201 while (p2->p_pid == nextpid || 202 p2->p_pgrp->pg_id == nextpid) { 203 nextpid++; 204 if (nextpid >= pidchecked) 205 goto retry; 206 } 207 if (p2->p_pid > nextpid && pidchecked > p2->p_pid) 208 pidchecked = p2->p_pid; 209 if (p2->p_pgrp->pg_id > nextpid && 210 pidchecked > p2->p_pgrp->pg_id) 211 pidchecked = p2->p_pgrp->pg_id; 212 } 213 if (!doingzomb) { 214 doingzomb = 1; |
215 p2 = zombproc; | 215 p2 = zombproc.lh_first; |
216 goto again; 217 } 218 } 219 | 216 goto again; 217 } 218 } 219 |
220 221 /* 222 * Link onto allproc (this should probably be delayed). 223 * Heavy use of volatile here to prevent the compiler from 224 * rearranging code. Yes, it *is* terribly ugly, but at least 225 * it works. 226 */ | |
227 p2 = newproc; | 220 p2 = newproc; |
228#define Vp2 ((volatile struct proc *)p2) 229 Vp2->p_stat = SIDL; /* protect against others */ 230 Vp2->p_pid = nextpid; 231 /* 232 * This is really: 233 * p2->p_next = allproc; 234 * allproc->p_prev = &p2->p_next; 235 * p2->p_prev = &allproc; 236 * allproc = p2; 237 * The assignment via allproc is legal since it is never NULL. 238 */ 239 *(volatile struct proc **)&Vp2->p_next = allproc; 240 *(volatile struct proc ***)&allproc->p_prev = 241 (volatile struct proc **)&Vp2->p_next; 242 *(volatile struct proc ***)&Vp2->p_prev = &allproc; 243 allproc = Vp2; 244#undef Vp2 | 221 p2->p_stat = SIDL; /* protect against others */ 222 p2->p_pid = nextpid; 223 LIST_INSERT_HEAD(&allproc, p2, p_list); |
245 p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */ | 224 p2->p_forw = p2->p_back = NULL; /* shouldn't be necessary */ |
225 LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash); |
|
246 | 226 |
247 /* Insert on the hash chain. */ 248 hash = &pidhash[PIDHASH(p2->p_pid)]; 249 p2->p_hash = *hash; 250 *hash = p2; 251 | |
252 /* 253 * Make a proc table entry for the new process. 254 * Start by zeroing the section of proc that is zero-initialized, 255 * then copy the section that is copied directly from the parent. 256 */ 257 bzero(&p2->p_startzero, 258 (unsigned) ((caddr_t)&p2->p_endzero - (caddr_t)&p2->p_startzero)); 259 bcopy(&p1->p_startcopy, &p2->p_startcopy, --- 37 unchanged lines hidden (view full) --- 297 p2->p_limit = p1->p_limit; 298 p2->p_limit->p_refcnt++; 299 } 300 301 if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT) 302 p2->p_flag |= P_CONTROLT; 303 if (forktype == ISVFORK) 304 p2->p_flag |= P_PPWAIT; | 227 /* 228 * Make a proc table entry for the new process. 229 * Start by zeroing the section of proc that is zero-initialized, 230 * then copy the section that is copied directly from the parent. 231 */ 232 bzero(&p2->p_startzero, 233 (unsigned) ((caddr_t)&p2->p_endzero - (caddr_t)&p2->p_startzero)); 234 bcopy(&p1->p_startcopy, &p2->p_startcopy, --- 37 unchanged lines hidden (view full) --- 272 p2->p_limit = p1->p_limit; 273 p2->p_limit->p_refcnt++; 274 } 275 276 if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT) 277 p2->p_flag |= P_CONTROLT; 278 if (forktype == ISVFORK) 279 p2->p_flag |= P_PPWAIT; |
305 p2->p_pgrpnxt = p1->p_pgrpnxt; 306 p1->p_pgrpnxt = p2; | 280 LIST_INSERT_AFTER(p1, p2, p_pglist); |
307 p2->p_pptr = p1; | 281 p2->p_pptr = p1; |
308 p2->p_osptr = p1->p_cptr; 309 if (p1->p_cptr) 310 p1->p_cptr->p_ysptr = p2; 311 p1->p_cptr = p2; | 282 LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling); 283 LIST_INIT(&p2->p_children); 284 |
312#ifdef KTRACE 313 /* 314 * Copy traceflag and tracefile if enabled. 315 * If not inherited, these were zeroed above. 316 */ 317 if (p1->p_traceflag&KTRFAC_INHERIT) { 318 p2->p_traceflag = p1->p_traceflag; 319 if ((p2->p_tracep = p1->p_tracep) != NULL) --- 74 unchanged lines hidden --- | 285#ifdef KTRACE 286 /* 287 * Copy traceflag and tracefile if enabled. 288 * If not inherited, these were zeroed above. 289 */ 290 if (p1->p_traceflag&KTRFAC_INHERIT) { 291 p2->p_traceflag = p1->p_traceflag; 292 if ((p2->p_tracep = p1->p_tracep) != NULL) --- 74 unchanged lines hidden --- |