summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c4
-rw-r--r--sys/kern/kern_fork.c102
-rw-r--r--sys/kern/kern_kthread.c4
3 files changed, 51 insertions, 59 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 4bf07b1ff1c..c71301dd274 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.44 2000/01/28 19:45:04 art Exp $ */
+/* $OpenBSD: init_main.c,v 1.45 2000/01/31 01:09:10 deraadt Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -399,7 +399,7 @@ main(framep)
siginit(p);
/* Create process 1 (init(8)). */
- if (fork1(p, FORK_FORK, NULL, 0, rval))
+ if (fork1(p, ISFORK, 0, NULL, 0, rval))
panic("fork init");
#ifdef cpu_set_init_frame /* XXX should go away */
if (rval[1]) {
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 3afd104709e..f355abab4a7 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.25 2000/01/28 19:45:04 art Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.26 2000/01/31 01:09:10 deraadt Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -78,7 +78,7 @@ sys_fork(p, v, retval)
void *v;
register_t *retval;
{
- return (fork1(p, FORK_FORK, NULL, 0, retval));
+ return (fork1(p, ISFORK, 0, NULL, 0, retval));
}
/*ARGSUSED*/
@@ -88,7 +88,7 @@ sys_vfork(p, v, retval)
void *v;
register_t *retval;
{
- return (fork1(p, FORK_VFORK|FORK_PPWAIT, NULL, 0, retval));
+ return (fork1(p, ISVFORK, 0, NULL, 0, retval));
}
int
@@ -100,41 +100,15 @@ sys_rfork(p, v, retval)
struct sys_rfork_args /* {
syscallarg(int) flags;
} */ *uap = v;
- int rforkflags;
- int flags;
-
- flags = FORK_RFORK;
- rforkflags = SCARG(uap, flags);
-
- if ((rforkflags & RFPROC) == 0)
- return (EINVAL);
-
- switch(rforkflags & (RFFDG|RFCFDG)) {
- case (RFFDG|RFCFDG):
- return EINVAL;
- case RFCFDG:
- flags |= FORK_CLEANFILES;
- break;
- case RFFDG:
- break;
- default:
- flags |= FORK_SHAREFILES;
- break;
- }
-
- if (rforkflags & RFNOWAIT)
- flags |= FORK_NOZOMBIE;
- if (rforkflags & RFMEM)
- flags |= FORK_SHAREVM;
-
- return (fork1(p, flags, NULL, 0, retval));
+ return (fork1(p, ISRFORK, SCARG(uap, flags), NULL, 0, retval));
}
int
-fork1(p1, flags, stack, stacksize, retval)
+fork1(p1, forktype, rforkflags, stack, stacksize, retval)
register struct proc *p1;
- int flags;
+ int forktype;
+ int rforkflags;
void *stack;
size_t stacksize;
register_t *retval;
@@ -145,8 +119,21 @@ fork1(p1, flags, stack, stacksize, retval)
struct vmspace *vm;
int count;
static int pidchecked = 0;
+ int dupfd = 1, cleanfd = 0;
vaddr_t uaddr;
+ if (forktype == ISRFORK) {
+ dupfd = 0;
+ if ((rforkflags & RFPROC) == 0)
+ return (EINVAL);
+ if ((rforkflags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG))
+ return (EINVAL);
+ if (rforkflags & RFFDG)
+ dupfd = 1;
+ if (rforkflags & RFCFDG)
+ cleanfd = 1;
+ }
+
/*
* Although process entries are dynamically created, we still keep
* a global limit on the maximum number we will create. We reserve
@@ -270,12 +257,12 @@ again:
if (p2->p_textvp)
VREF(p2->p_textvp);
- if (flags & FORK_CLEANFILES)
+ if (cleanfd)
p2->p_fd = fdinit(p1);
- else if (flags & FORK_SHAREFILES)
- p2->p_fd = fdshare(p1);
- else
+ else if (dupfd)
p2->p_fd = fdcopy(p1);
+ else
+ p2->p_fd = fdshare(p1);
/*
* If p_limit is still copy-on-write, bump refcnt,
@@ -292,11 +279,11 @@ again:
if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
p2->p_flag |= P_CONTROLT;
- if (flags & FORK_PPWAIT)
+ if (forktype == ISVFORK)
p2->p_flag |= P_PPWAIT;
LIST_INSERT_AFTER(p1, p2, p_pglist);
p2->p_pptr = p1;
- if (flags & FORK_NOZOMBIE)
+ if (forktype == ISRFORK && (rforkflags & RFNOWAIT))
p2->p_flag |= P_NOZOMBIE;
LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
LIST_INIT(&p2->p_children);
@@ -306,7 +293,7 @@ again:
* Copy traceflag and tracefile if enabled.
* If not inherited, these were zeroed above.
*/
- if (p1->p_traceflag & KTRFAC_INHERIT) {
+ if (p1->p_traceflag&KTRFAC_INHERIT) {
p2->p_traceflag = p1->p_traceflag;
if ((p2->p_tracep = p1->p_tracep) != NULL)
VREF(p2->p_tracep);
@@ -327,7 +314,7 @@ again:
p1->p_holdcnt++;
#if !defined(UVM) /* We do this later for UVM */
- if (flags & FORK_SHAREVM)
+ if (forktype == ISRFORK && (rforkflags & RFMEM)) {
/* share as much address space as possible */
(void) vm_map_inherit(&p1->p_vmspace->vm_map,
VM_MIN_ADDRESS, VM_MAXUSER_ADDRESS - MAXSSIZ,
@@ -357,23 +344,28 @@ again:
* different path later.
*/
#if defined(UVM)
- uvm_fork(p1, p2, ((flags & FORK_SHAREVM) ? TRUE : FALSE), stack,
- stacksize);
+ uvm_fork(p1, p2,
+ (forktype == ISRFORK && (rforkflags & RFMEM)) ? TRUE : FALSE,
+ stack, stacksize);
#else /* UVM */
vm_fork(p1, p2, stack, stacksize);
#endif /* UVM */
#endif
vm = p2->p_vmspace;
- if (flags & FORK_FORK) {
- forkstat.cntfork++;
- forkstat.sizfork += vm->vm_dsize + vm->vm_ssize;
- } else if (flags & FORK_VFORK) {
- forkstat.cntvfork++;
- forkstat.sizvfork += vm->vm_dsize + vm->vm_ssize;
- } else if (flags & FORK_RFORK) {
- forkstat.cntrfork++;
- forkstat.sizrfork += vm->vm_dsize + vm->vm_ssize;
+ switch (forktype) {
+ case ISFORK:
+ forkstat.cntfork++;
+ forkstat.sizfork += vm->vm_dsize + vm->vm_ssize;
+ break;
+ case ISVFORK:
+ forkstat.cntvfork++;
+ forkstat.sizvfork += vm->vm_dsize + vm->vm_ssize;
+ break;
+ case ISRFORK:
+ forkstat.cntrfork++;
+ forkstat.sizrfork += vm->vm_dsize + vm->vm_ssize;
+ break;
}
/*
@@ -393,9 +385,9 @@ again:
#if defined(UVM)
uvmexp.forks++;
- if (flags & FORK_PPWAIT)
+ if (forktype == ISVFORK)
uvmexp.forks_ppwait++;
- if (flags & FORK_SHAREVM)
+ if (forktype == ISRFORK && (rforkflags & RFMEM))
uvmexp.forks_sharevm++;
#endif
@@ -404,7 +396,7 @@ again:
* child to exec or exit, set P_PPWAIT on child, and sleep on our
* proc (in case of exit).
*/
- if (flags & FORK_PPWAIT)
+ if (forktype == ISVFORK)
while (p2->p_flag & P_PPWAIT)
tsleep(p1, PWAIT, "ppwait", 0);
diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c
index c5daef62143..b4eef9770f5 100644
--- a/sys/kern/kern_kthread.c
+++ b/sys/kern/kern_kthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_kthread.c,v 1.5 2000/01/28 19:45:04 art Exp $ */
+/* $OpenBSD: kern_kthread.c,v 1.6 2000/01/31 01:09:10 deraadt Exp $ */
/* $NetBSD: kern_kthread.c,v 1.3 1998/12/22 21:21:36 kleink Exp $ */
/*-
@@ -83,7 +83,7 @@ kthread_create(func, arg, newpp, fmt, va_alist)
* descriptors and don't leave the exit status around for the
* parent to wait for.
*/
- error = fork1(&proc0, FORK_RFORK|FORK_SHAREVM|FORK_NOZOMBIE, NULL,
+ error = fork1(&proc0, ISRFORK, RFPROC | RFMEM | RFFDG | RFNOWAIT, NULL,
0, rv);
if (error)
return (error);