rktio: repairs for Linux

This commit is contained in:
Matthew Flatt 2017-06-11 15:36:13 -06:00
parent 6e1d519711
commit 72b0351331
7 changed files with 88 additions and 19 deletions

View File

@ -3,6 +3,8 @@ srcdir = @srcdir@
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ @CPPFLAGS@ CFLAGS = @CFLAGS@ @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
RKTIO_HEADERS = $(srcdir)/rktio.h $(srcdir)/rktio_private.h rktio_config.h RKTIO_HEADERS = $(srcdir)/rktio.h $(srcdir)/rktio_private.h rktio_config.h
@ -20,7 +22,7 @@ demo: rktio_demo
./rktio_demo ./rktio_demo
rktio_demo: $(OBJS) demo.o demo_fifo rktio_demo: $(OBJS) demo.o demo_fifo
$(CC) -o rktio_demo $(CFLAGS) $(LDFLAGS) demo.o $(OBJS) $(CC) -o rktio_demo $(CFLAGS) $(LDFLAGS) demo.o $(OBJS) $(LIBS)
demo_fifo: demo_fifo:
mkfifo demo_fifo mkfifo demo_fifo
@ -48,3 +50,6 @@ rktio_main.o: $(srcdir)/rktio_main.c $(RKTIO_HEADERS)
demo.o: $(srcdir)/demo.c $(RKTIO_HEADERS) demo.o: $(srcdir)/demo.c $(RKTIO_HEADERS)
$(CC) $(CFLAGS) -I$(srcdir) -I. -o demo.o -c $(srcdir)/demo.c $(CC) $(CFLAGS) -I$(srcdir) -I. -o demo.o -c $(srcdir)/demo.c
clean:
rm -f $(OBJS) rktio_demo

View File

@ -3015,6 +3015,51 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmod in -lm" >&5
$as_echo_n "checking for fmod in -lm... " >&6; }
if ${ac_cv_lib_m_fmod+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char fmod ();
int
main ()
{
return fmod ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_m_fmod=yes
else
ac_cv_lib_m_fmod=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_fmod" >&5
$as_echo "$ac_cv_lib_m_fmod" >&6; }
if test "x$ac_cv_lib_m_fmod" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBM 1
_ACEOF
LIBS="-lm $LIBS"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
$as_echo_n "checking for dlopen in -ldl... " >&6; } $as_echo_n "checking for dlopen in -ldl... " >&6; }
if ${ac_cv_lib_dl_dlopen+:} false; then : if ${ac_cv_lib_dl_dlopen+:} false; then :

View File

@ -14,6 +14,7 @@ AC_CANONICAL_SYSTEM
AC_PROG_CC AC_PROG_CC
AC_CHECK_LIB(m, fmod)
AC_CHECK_LIB(dl, dlopen) AC_CHECK_LIB(dl, dlopen)
############## platform tests ################ ############## platform tests ################

View File

@ -507,8 +507,8 @@ int main()
} }
check_valid(saw_file); check_valid(saw_file);
/* We expect `lt` to work on regular files everywhere except Windows: */ /* We expect `lt` to work on regular files except on Windows and epoll: */
#if !defined(RKTIO_SYSTEM_WINDOWS) && !defined(HAVE_KQUEUE_SYSCALL) #if !defined(RKTIO_SYSTEM_WINDOWS) && !defined(HAVE_EPOLL_SYSCALL)
fd = rktio_open(rktio, "test1", RKTIO_OPEN_READ); fd = rktio_open(rktio, "test1", RKTIO_OPEN_READ);
check_valid(fd); check_valid(fd);
fd2 = rktio_open(rktio, "test1", RKTIO_OPEN_WRITE | RKTIO_OPEN_CAN_EXIST); fd2 = rktio_open(rktio, "test1", RKTIO_OPEN_WRITE | RKTIO_OPEN_CAN_EXIST);

View File

@ -11,7 +11,6 @@
# include <fcntl.h> # include <fcntl.h>
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#include <uuid/uuid.h>
#include <dirent.h> #include <dirent.h>
#endif #endif
@ -30,6 +29,10 @@
# define BIG_OFF_T_IZE(n) n # define BIG_OFF_T_IZE(n) n
#endif #endif
#if defined(__linux__)
# define DIRENT_NO_NAMLEN
#endif
#if defined(RKTIO_SYSTEM_UNIX) && !defined(NO_UNIX_USERS) #if defined(RKTIO_SYSTEM_UNIX) && !defined(NO_UNIX_USERS)
static int have_user_ids = 0; static int have_user_ids = 0;
static uid_t uid; static uid_t uid;

View File

@ -15,7 +15,11 @@
#ifdef HAVE_POLL_SYSCALL #ifdef HAVE_POLL_SYSCALL
# include <poll.h> # include <poll.h>
#endif #endif
#ifdef HAVE_EPOLL_SYSCALL
# include <sys/epoll.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
struct rktio_ltps_t { struct rktio_ltps_t {
#if defined(HAVE_KQUEUE_SYSCALL) || defined(HAVE_EPOLL_SYSCALL) #if defined(HAVE_KQUEUE_SYSCALL) || defined(HAVE_EPOLL_SYSCALL)
@ -154,7 +158,7 @@ rktio_ltps_handle_t *rktio_ltps_get_signaled_handle(rktio_t *rktio, rktio_ltps_t
static void log_kqueue_error(const char *action, int kr) static void log_kqueue_error(const char *action, int kr)
{ {
if (kr < 0) { if (kr < 0) {
fprintf(stderr, "%s error at %s: %d", fprintf(stderr, "%s error at %s: %d\n",
#ifdef HAVE_KQUEUE_SYSCALL #ifdef HAVE_KQUEUE_SYSCALL
"kqueue", "kqueue",
#else #else
@ -307,7 +311,7 @@ rktio_ltps_handle_t *rktio_ltps_add(rktio_t *rktio, rktio_ltps_t *lt, rktio_fd_t
# elif defined(HAVE_EPOLL_SYSCALL) # elif defined(HAVE_EPOLL_SYSCALL)
{ {
struct epoll_event ev; struct epoll_event ev;
int already = !RKTIO_FALSEP(RKTIO_VEC_ELS(v)[1]), kr; int already = !!v->write_handle, kr;
memset(&ev, 0, sizeof(ev)); memset(&ev, 0, sizeof(ev));
ev.data.fd = fd; ev.data.fd = fd;
ev.events = EPOLLIN | (already ? EPOLLOUT : 0); ev.events = EPOLLIN | (already ? EPOLLOUT : 0);
@ -344,7 +348,7 @@ rktio_ltps_handle_t *rktio_ltps_add(rktio_t *rktio, rktio_ltps_t *lt, rktio_fd_t
# elif defined(HAVE_EPOLL_SYSCALL) # elif defined(HAVE_EPOLL_SYSCALL)
{ {
struct epoll_event ev; struct epoll_event ev;
int already = !RKTIO_FALSEP(RKTIO_VEC_ELS(v)[0]), kr; int already = !!v->read_handle, kr;
memset(&ev, 0, sizeof(ev)); memset(&ev, 0, sizeof(ev));
ev.data.fd = fd; ev.data.fd = fd;
ev.events = EPOLLOUT | (already ? EPOLLIN : 0); ev.events = EPOLLOUT | (already ? EPOLLIN : 0);

View File

@ -1405,7 +1405,7 @@ void rktio_listen_stop(rktio_t *rktio, rktio_listener_t *l)
free(l); free(l);
} }
int rktio_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener) static int do_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener, int report_which)
{ {
int sr, i; int sr, i;
@ -1415,10 +1415,13 @@ int rktio_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener)
} while ((sr == -1) && (errno == EINTR)); } while ((sr == -1) && (errno == EINTR));
if (sr > 0) { if (sr > 0) {
for (i = listener->count; i--; ) { if (report_which) {
if (listener->pfd[i].revents) for (i = listener->count; i--; ) {
return i + 1; if (listener->pfd[i].revents)
} return i + 1;
}
} else
return RKTIO_POLL_READY;
} }
if (sr == -1) { if (sr == -1) {
@ -1452,12 +1455,15 @@ int rktio_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener)
} while ((sr == -1) && (NOT_WINSOCK(errno) == EINTR)); } while ((sr == -1) && (NOT_WINSOCK(errno) == EINTR));
if (sr > 0) { if (sr > 0) {
for (i = 0; i < listener->count; i++) { if (report_which) {
s = listener->s[i]; for (i = 0; i < listener->count; i++) {
if (RKTIO_SOCK_FD_ISSET(s, readfds) s = listener->s[i];
|| RKTIO_SOCK_FD_ISSET(s, exnfds)) if (RKTIO_SOCK_FD_ISSET(s, readfds)
return i + 1; || RKTIO_SOCK_FD_ISSET(s, exnfds))
} return i + 1;
}
} else
return RKTIO_POLL_READY;
} }
if (sr == -1) { if (sr == -1) {
@ -1468,6 +1474,11 @@ int rktio_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener)
#endif #endif
} }
int rktio_poll_accept_ready(rktio_t *rktio, rktio_listener_t *listener)
{
return do_poll_accept_ready(rktio, listener, 0);
}
void rktio_poll_add_receive(rktio_t *rktio, rktio_listener_t *listener, rktio_poll_set_t *fds) void rktio_poll_add_receive(rktio_t *rktio, rktio_listener_t *listener, rktio_poll_set_t *fds)
{ {
int i; int i;
@ -1490,7 +1501,7 @@ rktio_fd_t *rktio_accept(rktio_t *rktio, rktio_listener_t *listener)
unsigned int l; unsigned int l;
char tcp_accept_addr[RKTIO_SOCK_NAME_MAX_LEN]; char tcp_accept_addr[RKTIO_SOCK_NAME_MAX_LEN];
ready_pos = rktio_poll_accept_ready(rktio, listener); ready_pos = do_poll_accept_ready(rktio, listener, 1);
if (!ready_pos) { if (!ready_pos) {
set_racket_error(RKTIO_ERROR_ACCEPT_NOT_READY); set_racket_error(RKTIO_ERROR_ACCEPT_NOT_READY);
return NULL; return NULL;