Use a special version of dup

libsystem_kernel's `sys_dup` and `sys_dup2` call `kqueue_dup`, so if we
use the normal `dup` call in libkqueue, we end up recursing back into
libkqueue (unecessarily).
This commit is contained in:
Ariel Abreu 2022-03-09 17:13:29 -05:00
parent f3f8cb99b0
commit 8b748d1070
No known key found for this signature in database
GPG Key ID: D67AE16CCEA85B70
3 changed files with 9 additions and 3 deletions

View File

@ -69,7 +69,9 @@ extern long int syscall (long int __sysno, ...);
*/
#define KNOTE_PLATFORM_SPECIFIC \
int kn_epollfd; /* A copy of filter->epfd */ \
char kn_extra_buffer[64]; /* Extra data buffer used by some filters (EVFILT_MACHPORT) */ \
union { \
char kn_extra_buffer[64]; /* Extra data buffer used by some filters (EVFILT_MACHPORT) */ \
}; \
union { \
int kn_timerfd; \
int kn_signalfd; \

View File

@ -28,6 +28,8 @@
#include <string.h>
#include <unistd.h>
#include <darling/emulation/ext/for-libkqueue.h>
#include "private.h"
/*
@ -185,7 +187,7 @@ evfilt_read_knote_create(struct filter *filt, struct knote *kn)
return (0);
}
else {
kn->kdata.kn_dupfd = dup(kn->kev.ident);
kn->kdata.kn_dupfd = _dup_4libkqueue(kn->kev.ident);
fcntl(kn->kdata.kn_dupfd, F_SETFD, FD_CLOEXEC);
if (epoll_ctl(kn->kn_epollfd, EPOLL_CTL_ADD, kn->kdata.kn_dupfd, &ev) < 0) {
dbg_printf("epoll_ctl(2): %s", strerror(errno));

View File

@ -28,6 +28,8 @@
#include <string.h>
#include <unistd.h>
#include <darling/emulation/ext/for-libkqueue.h>
#include "private.h"
int
@ -82,7 +84,7 @@ evfilt_socket_knote_create(struct filter *filt, struct knote *kn)
ev.data.ptr = kn;
/* Duplicate the fd to workaround epoll's poor design */
kn->kdata.kn_dupfd = dup(kn->kev.ident);
kn->kdata.kn_dupfd = _dup_4libkqueue(kn->kev.ident);
if (epoll_ctl(kn->kn_epollfd, EPOLL_CTL_ADD, kn->kdata.kn_dupfd, &ev) < 0) {
dbg_printf("epoll_ctl(2): %s", strerror(errno));