summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread/uthread_dup.c
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2003-02-04 22:14:28 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2003-02-04 22:14:28 +0000
commit5f11a81a04b25b7f64a86ad418f79529df7cae52 (patch)
tree5f656a0decb261f61791bf87d1919c2f25de511a /lib/libpthread/uthread/uthread_dup.c
parent0691abffebb064ad7318896c4ee8b0a26b049654 (diff)
Part 1 of thread fd handling fixes. In the new scheme fd_table_entries
for dup-ed fds are shared to ensure proper flag handling. A refcnt was added to control when entries should be freed. Specific changes: close: don't free entry unless refcnt is zero dup: rewrite to use new function _thread_fd_table_dup dup2: rewrite to use new function _thread_fd_table_dup fcntl: use _thread_fd_table_dup uthread_fd: initialize thread fd table, searching for dup-ed fds. Add function to share _thread_fd_table entries when an fd is dup-ed. uthread_init: make it readable. Call fd init functions. All current regression tests plus the mysql torture test pass. The new stdfiles regression test fails (I/O redirection problem). Part 2 is intended to fix that problem
Diffstat (limited to 'lib/libpthread/uthread/uthread_dup.c')
-rw-r--r--lib/libpthread/uthread/uthread_dup.c64
1 files changed, 8 insertions, 56 deletions
diff --git a/lib/libpthread/uthread/uthread_dup.c b/lib/libpthread/uthread/uthread_dup.c
index 8aba9a1dba6..ad1adc3081d 100644
--- a/lib/libpthread/uthread/uthread_dup.c
+++ b/lib/libpthread/uthread/uthread_dup.c
@@ -1,37 +1,6 @@
-/* $OpenBSD: uthread_dup.c,v 1.3 1999/11/25 07:01:33 d Exp $ */
-/*
- * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by John Birrell.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: uthread_dup.c,v 1.5 1999/08/28 00:03:29 peter Exp $
- */
+/* $OpenBSD: uthread_dup.c,v 1.4 2003/02/04 22:14:27 marc Exp $ */
+/* PUBLIC DOMAIN <marc@snafu.org> */
+
#include <unistd.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
@@ -42,30 +11,13 @@ dup(int fd)
{
int ret;
- /* Lock the file descriptor: */
- if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
- /* Perform the 'dup' syscall: */
- if ((ret = _thread_sys_dup(fd)) < 0) {
- }
- /* Initialise the file descriptor table entry: */
- else if (_thread_fd_table_init(ret) != 0) {
- /* Quietly close the file: */
- _thread_sys_close(ret);
-
- /* Reset the file descriptor: */
- ret = -1;
- } else {
- /*
- * Save the file open flags so that they can be
- * checked later:
- */
- _thread_fd_table[ret]->flags = _thread_fd_table[fd]->flags;
- }
-
- /* Unlock the file descriptor: */
+ ret = _FD_LOCK(fd, FD_RDWR, NULL);
+ if (ret == 0) {
+ ret = _thread_sys_dup(fd);
+ if (ret != -1)
+ ret = _thread_fd_table_dup(fd, ret);
_FD_UNLOCK(fd, FD_RDWR);
}
- /* Return the completion status: */
return (ret);
}
#endif