From 15d9246bb21b1ea9c05d45865d563128f7c319e7 Mon Sep 17 00:00:00 2001 From: pooka Date: Thu, 11 Jul 2002 10:37:26 +0000 Subject: [PATCH] Add FORK_NOWAIT flag, which sets init as the parent of the forked process. Useful for FreeBSD rfork() emulation. ok'd by Christos --- sys/kern/kern_fork.c | 8 ++++---- sys/sys/proc.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 34f49d3ea59c..25554b0b64d9 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_fork.c,v 1.89 2002/06/17 16:22:50 christos Exp $ */ +/* $NetBSD: kern_fork.c,v 1.90 2002/07/11 10:37:26 pooka Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.89 2002/06/17 16:22:50 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.90 2002/07/11 10:37:26 pooka Exp $"); #include "opt_ktrace.h" #include "opt_systrace.h" @@ -407,8 +407,8 @@ fork1(struct proc *p1, int flags, int exitsig, void *stack, size_t stacksize, if (flags & FORK_PPWAIT) p2->p_flag |= P_PPWAIT; LIST_INSERT_AFTER(p1, p2, p_pglist); - p2->p_pptr = p1; - LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling); + p2->p_pptr = (flags & FORK_NOWAIT) ? initproc : p1; + LIST_INSERT_HEAD(&p2->p_pptr->p_children, p2, p_sibling); LIST_INIT(&p2->p_children); callout_init(&p2->p_realit_ch); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index ff2252287ce6..5c5018c57fca 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $NetBSD: proc.h,v 1.140 2002/07/04 23:32:15 thorpej Exp $ */ +/* $NetBSD: proc.h,v 1.141 2002/07/11 10:37:27 pooka Exp $ */ /*- * Copyright (c) 1986, 1989, 1991, 1993 @@ -366,6 +366,7 @@ do { \ #define FORK_SHARECWD 0x04 /* Share cdir/rdir/cmask */ #define FORK_SHAREFILES 0x08 /* Share file descriptors */ #define FORK_SHARESIGS 0x10 /* Share signal actions */ +#define FORK_NOWAIT 0x20 /* Make init the parent of the child */ #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;