aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2004-11-07 12:39:28 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2004-11-07 12:39:28 +0000
commit8ec21e3a681045e210cc6393cecee86fab14bb6e (patch)
treeb778d7d845b50f925b6ffecdf43d8852fd9a5b5e
parent5ecb9278bc2a182be938638e38884d8da41e2add (diff)
downloadsrc-8ec21e3a681045e210cc6393cecee86fab14bb6e.tar.gz
src-8ec21e3a681045e210cc6393cecee86fab14bb6e.zip
Allow fdinit() to be called with a NULL fdp argument so we can use
it when setting up init. Make fdinit() lock the fdp argument as needed.
Notes
Notes: svn path=/head/; revision=137331
-rw-r--r--sys/kern/init_main.c17
-rw-r--r--sys/kern/kern_descrip.c31
-rw-r--r--sys/kern/kern_fork.c4
3 files changed, 19 insertions, 33 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index e23e44608108..4b94b5baa8d3 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -91,7 +91,6 @@ static struct pgrp pgrp0;
struct proc proc0;
struct thread thread0;
struct ksegrp ksegrp0;
-static struct filedesc0 filedesc0;
struct vmspace vmspace0;
struct proc *initproc;
@@ -314,9 +313,8 @@ struct sysentvec null_sysvec = {
static void
proc0_init(void *dummy __unused)
{
- register struct proc *p;
- register struct filedesc0 *fdp;
- register unsigned i;
+ struct proc *p;
+ unsigned i;
struct thread *td;
struct ksegrp *kg;
@@ -406,17 +404,8 @@ proc0_init(void *dummy __unused)
siginit(&proc0);
/* Create the file descriptor table. */
- /* XXX this duplicates part of fdinit() */
- fdp = &filedesc0;
- p->p_fd = &fdp->fd_fd;
+ p->p_fd = fdinit(NULL);
p->p_fdtol = NULL;
- mtx_init(&fdp->fd_fd.fd_mtx, FILEDESC_LOCK_DESC, NULL, MTX_DEF);
- fdp->fd_fd.fd_refcnt = 1;
- fdp->fd_fd.fd_cmask = CMASK;
- fdp->fd_fd.fd_ofiles = fdp->fd_dfiles;
- fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
- fdp->fd_fd.fd_nfiles = NDFILE;
- fdp->fd_fd.fd_map = fdp->fd_dmap;
/* Create the limits structures. */
p->p_limit = lim_alloc();
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 132f326cbda7..85beee076205 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1403,22 +1403,21 @@ fdinit(fdp)
{
struct filedesc0 *newfdp;
- FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
-
- FILEDESC_UNLOCK(fdp);
- MALLOC(newfdp, struct filedesc0 *, sizeof(struct filedesc0),
- M_FILEDESC, M_WAITOK | M_ZERO);
- FILEDESC_LOCK(fdp);
+ newfdp = malloc(sizeof *newfdp, M_FILEDESC, M_WAITOK | M_ZERO);
mtx_init(&newfdp->fd_fd.fd_mtx, FILEDESC_LOCK_DESC, NULL, MTX_DEF);
- newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
- if (newfdp->fd_fd.fd_cdir)
- VREF(newfdp->fd_fd.fd_cdir);
- newfdp->fd_fd.fd_rdir = fdp->fd_rdir;
- if (newfdp->fd_fd.fd_rdir)
- VREF(newfdp->fd_fd.fd_rdir);
- newfdp->fd_fd.fd_jdir = fdp->fd_jdir;
- if (newfdp->fd_fd.fd_jdir)
- VREF(newfdp->fd_fd.fd_jdir);
+ if (fdp != NULL) {
+ FILEDESC_LOCK(fdp);
+ newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
+ if (newfdp->fd_fd.fd_cdir)
+ VREF(newfdp->fd_fd.fd_cdir);
+ newfdp->fd_fd.fd_rdir = fdp->fd_rdir;
+ if (newfdp->fd_fd.fd_rdir)
+ VREF(newfdp->fd_fd.fd_rdir);
+ newfdp->fd_fd.fd_jdir = fdp->fd_jdir;
+ if (newfdp->fd_fd.fd_jdir)
+ VREF(newfdp->fd_fd.fd_jdir);
+ FILEDESC_UNLOCK(fdp);
+ }
/* Create the file descriptor table. */
newfdp->fd_fd.fd_refcnt = 1;
@@ -1460,7 +1459,9 @@ fdcopy(fdp)
return (NULL);
FILEDESC_LOCK_ASSERT(fdp, MA_OWNED);
+ FILEDESC_UNLOCK(fdp);
newfdp = fdinit(fdp);
+ FILEDESC_LOCK(fdp);
while (fdp->fd_lastfile >= newfdp->fd_nfiles) {
FILEDESC_UNLOCK(fdp);
FILEDESC_LOCK(newfdp);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 714a1af63b59..f90ff3280c7d 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -225,9 +225,7 @@ fork1(td, flags, pages, procp)
*/
if (flags & RFCFDG) {
struct filedesc *fdtmp;
- FILEDESC_LOCK(td->td_proc->p_fd);
fdtmp = fdinit(td->td_proc->p_fd);
- FILEDESC_UNLOCK(td->td_proc->p_fd);
fdfree(td);
p1->p_fd = fdtmp;
}
@@ -423,9 +421,7 @@ again:
* Copy filedesc.
*/
if (flags & RFCFDG) {
- FILEDESC_LOCK(td->td_proc->p_fd);
fd = fdinit(td->td_proc->p_fd);
- FILEDESC_UNLOCK(td->td_proc->p_fd);
fdtol = NULL;
} else if (flags & RFFDG) {
FILEDESC_LOCK(p1->p_fd);