diff options
| author | 2002-02-05 16:02:27 +0000 | |
|---|---|---|
| committer | 2002-02-05 16:02:27 +0000 | |
| commit | 03e6dd169fa2570cc74742b3a12ccbc1489251aa (patch) | |
| tree | 4ca3c9953fabbc0fc10632f6d0e67fac87780a12 /sys/kern/sys_generic.c | |
| parent | use log interface and remove perror() in child. use (diff) | |
| download | wireguard-openbsd-03e6dd169fa2570cc74742b3a12ccbc1489251aa.tar.xz wireguard-openbsd-03e6dd169fa2570cc74742b3a12ccbc1489251aa.zip | |
Add counting of temporary references to a struct file (as opposed to references
from fd tables and other long-lived objects). This is to avoid races between
using a file descriptor and having another process (with shared fd table)
close it. We use a separate refence count so that error values from close(2)
will be correctly returned to the caller of close(2).
The macros for those reference counts are FILE_USE(fp) and FILE_UNUSE(fp).
Make sure that the cases where closef can be called "incorrectly" (most notably
dup2(2)) are handled.
Right now only callers of closef (and {,p}read) use FILE_{,UN}USE correctly,
more fixes incoming soon.
Diffstat (limited to 'sys/kern/sys_generic.c')
| -rw-r--r-- | sys/kern/sys_generic.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 575e4fc58c0..fd32b2a9959 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_generic.c,v 1.32 2002/02/02 16:05:58 art Exp $ */ +/* $OpenBSD: sys_generic.c,v 1.33 2002/02/05 16:02:27 art Exp $ */ /* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */ /* @@ -91,6 +91,8 @@ sys_read(p, v, retval) if ((fp->f_flag & FREAD) == 0) return (EBADF); + FILE_USE(fp); + /* dofileread() will unuse the descriptor for us */ return (dofileread(p, fd, fp, SCARG(uap, buf), SCARG(uap, nbyte), &fp->f_offset, retval)); @@ -152,9 +154,7 @@ dofileread(p, fd, fp, buf, nbyte, offset, retval) #endif *retval = cnt; out: -#if notyet - FILE_UNUSE(fp, p); -#endif + FILE_UNUSE(fp); return (error); } |
