summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2003-10-22 00:25:43 +0000
committerBrad Smith <brad@cvs.openbsd.org>2003-10-22 00:25:43 +0000
commitdc56f0f31575ebf6da4018b277282473204690a1 (patch)
tree1db2eb67c4b4e07aab1cfd67196f2d2fb046f955 /lib
parent5195883faed308e230f35a32d876751c910922ce (diff)
Add wrapper for kqueue() to keep track of the allocated fd and allow it to
be closed. This fixes a file descriptor leak when closing a kqueue() fd. from FreeBSD ok marc@
Diffstat (limited to 'lib')
-rw-r--r--lib/libpthread/sys/Makefile.inc6
-rw-r--r--lib/libpthread/uthread/Makefile.inc3
-rw-r--r--lib/libpthread/uthread/uthread_init.c3
-rw-r--r--lib/libpthread/uthread/uthread_kqueue.c55
4 files changed, 62 insertions, 5 deletions
diff --git a/lib/libpthread/sys/Makefile.inc b/lib/libpthread/sys/Makefile.inc
index 9aad9340db2..633c31d8b61 100644
--- a/lib/libpthread/sys/Makefile.inc
+++ b/lib/libpthread/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.11 2003/07/22 17:15:12 brad Exp $
+# $OpenBSD: Makefile.inc,v 1.12 2003/10/22 00:25:42 brad Exp $
.PATH: ${SRCDIR}/sys ${SRCDIR}/arch/${MACHINE_ARCH}
@@ -23,8 +23,8 @@ HIDDEN_SYSCALLS= accept.o bind.o close.o connect.o dup.o dup2.o \
execve.o fchflags.o fchmod.o fchown.o fcntl.o \
flock.o fpathconf.o fstat.o fstatfs.o fsync.o getdirentries.o \
getlogin.o getpeername.o getsockname.o getsockopt.o ioctl.o kevent.o \
- listen.o msync.o nanosleep.o open.o pipe.o poll.o read.o readv.o \
- recvfrom.o recvmsg.o sched_yield.o select.o sendmsg.o sendto.o \
+ kqueue.o listen.o msync.o nanosleep.o open.o pipe.o poll.o read.o \
+ readv.o recvfrom.o recvmsg.o sched_yield.o select.o sendmsg.o sendto.o \
setsockopt.o shutdown.o sigaction.o sigaltstack.o \
sigprocmask.o sigsuspend.o \
socket.o socketpair.o wait4.o write.o writev.o \
diff --git a/lib/libpthread/uthread/Makefile.inc b/lib/libpthread/uthread/Makefile.inc
index 4c1c840eee4..b37a3cf4fc3 100644
--- a/lib/libpthread/uthread/Makefile.inc
+++ b/lib/libpthread/uthread/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.14 2003/01/20 18:12:11 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.15 2003/10/22 00:25:42 brad Exp $
# $FreeBSD: Makefile.inc,v 1.19 1999/08/28 00:03:19 peter Exp $
# uthread sources
@@ -67,6 +67,7 @@ SRCS+= \
uthread_join.c \
uthread_kern.c \
uthread_kevent.c \
+ uthread_kqueue.c \
uthread_kill.c \
uthread_listen.c \
uthread_main_np.c \
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index a226a09b912..bb5bc1f34a4 100644
--- a/lib/libpthread/uthread/uthread_init.c
+++ b/lib/libpthread/uthread/uthread_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_init.c,v 1.29 2003/05/13 16:49:32 marc Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.30 2003/10/22 00:25:42 brad Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -100,6 +100,7 @@ static void *references[] = {
&getsockopt,
&ioctl,
&kevent,
+ &kqueue,
&listen,
&msync,
&nanosleep,
diff --git a/lib/libpthread/uthread/uthread_kqueue.c b/lib/libpthread/uthread/uthread_kqueue.c
new file mode 100644
index 00000000000..7ba41db1f48
--- /dev/null
+++ b/lib/libpthread/uthread/uthread_kqueue.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: uthread_kqueue.c,v 1.1 2003/10/22 00:25:42 brad Exp $ */
+
+/*
+ * Copyright (c) 2003 Mark Peek <mp@freebsd.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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_kqueue.c,v 1.1 2003/07/25 17:02:33 mp Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/event.h>
+#include <fcntl.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+int
+kqueue(void)
+{
+ int fd;
+
+ /* Create a kqueue: */
+ if ((fd = _thread_sys_kqueue()) < 0) {
+ /* Error creating socket. */
+
+ /* Initialise the entry in the file descriptor table: */
+ } else if (_thread_fd_table_init(fd) != 0) {
+ _thread_sys_close(fd);
+ fd = -1;
+ }
+ return (fd);
+}
+#endif