In handle_connect() we really need a blocking fd for the client.
authorAndre Noll <maan@systemlinux.org>
Fri, 23 Nov 2007 09:40:16 +0000 (10:40 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 23 Nov 2007 09:40:16 +0000 (10:40 +0100)
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
fd.c
fd.h

index c1bbba9aef86d7fccc936d2230f591ce3eb734d4..ab948b09b129546da1d62a515059deb013e6f50d 100644 (file)
--- 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);
 
        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 "
        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 ecd87cdccb555bafea525c3a5ded0063f2b63438..b78d266a613422f0319e4e6b4fb1d15c05cd2b60 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -60,6 +60,24 @@ int para_select(int n, fd_set *readfds, fd_set *writefds,
        return ret;
 }
 
        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.
  *
 /**
  * Set a file descriptor to non-blocking mode.
  *
diff --git a/fd.h b/fd.h
index 224f832cea2f0792085cf82a0c15f756fe84c489..c7aafc67337e4c3869f3221399517ec30f1b3375 100644 (file)
--- 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 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);
 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);