diff options
author | Niels Provos <provos@cvs.openbsd.org> | 1999-07-13 15:17:54 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 1999-07-13 15:17:54 +0000 |
commit | d0e661be14492b0bc5cc1cd3252e0a4302c8a350 (patch) | |
tree | de457786be963b3322bbd360c2a883f7466231fe /sys | |
parent | 7bb26b9d5348995f3970820e647e2058c0fa94c9 (diff) |
introduce fdremove() to mark a file descriptor as unused. fdremove makes
sure that the fd_freefile hints stay in sync, otherwise free file
descriptors might not be overlooked by fdalloc(); ok millert@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/compat/svr4/svr4_net.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_descrip.c | 11 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 4 | ||||
-rw-r--r-- | sys/kern/sys_pipe.c | 4 | ||||
-rw-r--r-- | sys/kern/uipc_syscalls.c | 12 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 8 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 3 |
7 files changed, 28 insertions, 18 deletions
diff --git a/sys/compat/svr4/svr4_net.c b/sys/compat/svr4/svr4_net.c index cbdc30b911d..4b9b85410b4 100644 --- a/sys/compat/svr4/svr4_net.c +++ b/sys/compat/svr4/svr4_net.c @@ -1,4 +1,4 @@ -/* $OpenBSD: svr4_net.c,v 1.8 1997/02/13 19:45:20 niklas Exp $ */ +/* $OpenBSD: svr4_net.c,v 1.9 1999/07/13 15:17:53 provos Exp $ */ /* $NetBSD: svr4_net.c,v 1.12 1996/09/07 12:40:51 mycroft Exp $ */ /* @@ -171,7 +171,7 @@ svr4_netopen(dev, flag, mode, p) if ((error = socreate(family, &so, type, protocol)) != 0) { DPRINTF(("socreate error %d\n", error)); - p->p_fd->fd_ofiles[fd] = 0; + fdremove(p->p_fd, fd); ffree(fp); return error; } diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 4b70a7a689c..9c07889018f 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.17 1999/02/26 05:10:40 art Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.18 1999/07/13 15:17:50 provos Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -363,6 +363,15 @@ finishdup(fdp, old, new, retval) return (0); } +void +fdremove(fdp, fd) + struct filedesc *fdp; + int fd; +{ + fdp->fd_ofiles[fd] = NULL; + fd_unused(fdp, fd); +} + int fdrelease(p, fd) struct proc *p; diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index f3d019fec0d..352efbb5321 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.29 1999/06/23 09:44:28 art Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.30 1999/07/13 15:17:50 provos Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -517,7 +517,7 @@ sys_execve(p, v, retval) "/dev/null", p); if ((error = vn_open(&nd, flags, 0)) != 0) { ffree(fp); - p->p_fd->fd_ofiles[indx] = NULL; + fdremove(p->p_fd, indx); break; } fp->f_flag = flags; diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 0a3b4733741..0673d952d38 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_pipe.c,v 1.15 1999/06/08 16:05:22 deraadt Exp $ */ +/* $OpenBSD: sys_pipe.c,v 1.16 1999/07/13 15:17:50 provos Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -201,7 +201,7 @@ sys_opipe(p, v, retval) return (0); free3: ffree(rf); - fdp->fd_ofiles[retval[0]] = NULL; + fdremove(fdp, retval[0]); free2: (void)pipeclose(wpipe); (void)pipeclose(rpipe); diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 11ac934a883..555cddb2b52 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.27 1999/06/15 17:46:32 deraadt Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.28 1999/07/13 15:17:51 provos Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -85,7 +85,7 @@ sys_socket(p, v, retval) error = socreate(SCARG(uap, domain), &so, SCARG(uap, type), SCARG(uap, protocol)); if (error) { - fdp->fd_ofiles[fd] = NULL; + fdremove(fdp, fd); ffree(fp); } else { fp->f_data = (caddr_t)so; @@ -328,10 +328,10 @@ sys_socketpair(p, v, retval) return (error); free4: ffree(fp2); - fdp->fd_ofiles[sv[1]] = NULL; + fdremove(fdp, sv[1]); free3: ffree(fp1); - fdp->fd_ofiles[sv[0]] = NULL; + fdremove(fdp, sv[0]); free2: (void)soclose(so2); free1: @@ -898,10 +898,10 @@ sys_opipe(p, v, retval) return (0); free4: ffree(wf); - fdp->fd_ofiles[retval[1]] = NULL; + fdremove(fdp, retval[1]); free3: ffree(rf); - fdp->fd_ofiles[retval[0]] = NULL; + fdremove(fdp, retval[0]); free2: (void)soclose(wso); free1: diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index f2f2892bb74..55ee96e9a02 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.57 1999/05/31 17:34:48 millert Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.58 1999/07/13 15:17:51 provos Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -892,7 +892,7 @@ sys_open(p, v, retval) } if (error == ERESTART) error = EINTR; - fdp->fd_ofiles[indx] = NULL; + fdremove(fdp, indx); return (error); } p->p_dupfd = 0; @@ -917,7 +917,7 @@ sys_open(p, v, retval) if (error) { (void) vn_close(vp, fp->f_flag, fp->f_cred, p); ffree(fp); - fdp->fd_ofiles[indx] = NULL; + fdremove(fdp, indx); return (error); } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); @@ -940,7 +940,7 @@ sys_open(p, v, retval) VOP_UNLOCK(vp, 0, p); (void) vn_close(vp, fp->f_flag, fp->f_cred, p); ffree(fp); - fdp->fd_ofiles[indx] = NULL; + fdremove(fdp, indx); return (error); } } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 1ff824447d0..60826702402 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filedesc.h,v 1.5 1996/04/21 22:31:44 deraadt Exp $ */ +/* $OpenBSD: filedesc.h,v 1.6 1999/07/13 15:17:52 provos Exp $ */ /* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */ /* @@ -105,6 +105,7 @@ struct filedesc *fdshare __P((struct proc *p)); struct filedesc *fdcopy __P((struct proc *p)); void fdfree __P((struct proc *p)); int fdrelease __P((struct proc *p, int)); +void fdremove __P((struct filedesc *, int)); void fdcloseexec __P((struct proc *)); int closef __P((struct file *, struct proc *)); |