From ddb2a14f84ace45a0faec7c3cf378751ea4ac7d8 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 23 Nov 2007 10:40:16 +0100 Subject: [PATCH] In handle_connect() we really need a blocking fd for the client. At least on NetBSD the fd returned by accept() might be in non-blocking mode. So introduce mark_fd_blocking() and use it in handle_connect(). --- command.c | 4 ++++ fd.c | 18 ++++++++++++++++++ fd.h | 1 + 3 files changed, 23 insertions(+) diff --git a/command.c b/command.c index c1bbba9a..ab948b09 100644 --- a/command.c +++ b/command.c @@ -698,6 +698,10 @@ int handle_connect(int fd, struct sockaddr_in *addr) signal(SIGHUP, SIG_DFL); signal(SIGUSR1, SIG_IGN); + /* we need a blocking fd here as recv() might return EAGAIN otherwise. */ + ret = mark_fd_blocking(fd); + if (ret < 0) + goto err_out; challenge_nr = random(); /* send Welcome message */ ret = send_va_buffer(fd, "This is para_server, version " diff --git a/fd.c b/fd.c index ecd87cdc..b78d266a 100644 --- a/fd.c +++ b/fd.c @@ -60,6 +60,24 @@ int para_select(int n, fd_set *readfds, fd_set *writefds, return ret; } +/** + * Set a file descriptor to blocking mode. + * + * \param fd The file descriptor. + * + * \return Standard. + */ +int mark_fd_blocking(int fd) +{ + int flags = fcntl(fd, F_GETFL); + if (flags < 0) + return -ERRNO_TO_PARA_ERROR(errno); + flags = fcntl(fd, F_SETFL, ((long)flags) & ~O_NONBLOCK); + if (flags < 0) + return -ERRNO_TO_PARA_ERROR(errno); + return 1; +} + /** * Set a file descriptor to non-blocking mode. * diff --git a/fd.h b/fd.h index 224f832c..c7aafc67 100644 --- a/fd.h +++ b/fd.h @@ -10,6 +10,7 @@ int file_exists(const char *); int para_select(int n, fd_set *readfds, fd_set *writefds, struct timeval *timeout_tv); int mark_fd_nonblock(int fd); +int mark_fd_blocking(int fd); void para_fd_set(int fd, fd_set *fds, int *max_fileno); __must_check int para_fgets(char *line, int size, FILE *f); void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset); -- 2.39.2