diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2006-10-03 02:59:37 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2006-10-03 02:59:37 +0000 |
commit | 985672e305143e6bee0ba4c190b0771bd2f8746e (patch) | |
tree | 7871ff1c7df149af49e577edfd6cd33900013b09 /lib/libpthread/uthread/uthread_recvmsg.c | |
parent | 07706ccde7070f5695b2b92d66775c561609d513 (diff) |
Last Part of file descriptor race and deadlock corrections.
When a fd enters the closing state prevent any threads from
polling the fd and reschedule the thread with the closing_fd
flag set. This fixes a class of deadlocks where a thread is
blocked waiting for data (that may never arrive) and a later
thread calls close() or dup2() on the fd. okay brad@
Diffstat (limited to 'lib/libpthread/uthread/uthread_recvmsg.c')
-rw-r--r-- | lib/libpthread/uthread/uthread_recvmsg.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/libpthread/uthread/uthread_recvmsg.c b/lib/libpthread/uthread/uthread_recvmsg.c index 5e8f13bd6dc..fa455395938 100644 --- a/lib/libpthread/uthread/uthread_recvmsg.c +++ b/lib/libpthread/uthread/uthread_recvmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_recvmsg.c,v 1.6 2006/09/22 19:04:33 kurt Exp $ */ +/* $OpenBSD: uthread_recvmsg.c,v 1.7 2006/10/03 02:59:36 kurt Exp $ */ /* * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -58,6 +58,7 @@ recvmsg(int fd, struct msghdr *msg, int flags) /* Set the timeout: */ _thread_kern_set_timeout(NULL); curthread->interrupted = 0; + curthread->closing_fd = 0; _thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__); /* Check if the wait was interrupted: */ @@ -66,6 +67,11 @@ recvmsg(int fd, struct msghdr *msg, int flags) errno = EINTR; ret = -1; break; + } else if (curthread->closing_fd) { + /* Return an error status: */ + errno = EBADF; + ret = -1; + break; } } else { ret = -1; |