summaryrefslogtreecommitdiff
path: root/sys/kern/uipc_usrreq.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-05 16:02:28 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-05 16:02:28 +0000
commit2bd7d345e3306e2e3a8559a8e61c740b13941bcf (patch)
tree9e4389e6d78e940e0f9f69eea5766eea51ebe503 /sys/kern/uipc_usrreq.c
parent88aba8a3432b32e750331cbeae4e915673df2073 (diff)
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/uipc_usrreq.c')
-rw-r--r--sys/kern/uipc_usrreq.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 0d04d9a80d5..80b05f89225 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.16 2002/02/02 16:05:58 art Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.17 2002/02/05 16:02:27 art Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -887,6 +887,7 @@ unp_gc()
if (fp->f_count == fp->f_msgcount && !(fp->f_flag & FMARK)) {
*fpp++ = fp;
nunref++;
+ FILE_USE(fp);
fp->f_count++;
}
}
@@ -894,7 +895,7 @@ unp_gc()
if ((*fpp)->f_type == DTYPE_SOCKET && (*fpp)->f_data != NULL)
sorflush((struct socket *)(*fpp)->f_data);
for (i = nunref, fpp = extra_ref; --i >= 0; ++fpp)
- (void) closef(*fpp, (struct proc *)0);
+ (void) closef(*fpp, NULL);
free((caddr_t)extra_ref, M_FILE);
unp_gcing = 0;
}
@@ -956,7 +957,8 @@ unp_discard(fp)
struct file *fp;
{
+ FILE_USE(fp);
fp->f_msgcount--;
unp_rights--;
- (void) closef(fp, (struct proc *)0);
+ (void) closef(fp, NULL);
}