From d5302b03b2728a27f14c4f260ce6a5247ea87c6e Mon Sep 17 00:00:00 2001 From: "Alan D. Brunelle" Date: Wed, 11 Feb 2009 11:42:09 -0500 Subject: [PATCH] Added accept as a system call needing resource increases accept(2) opens a socket, and thus needs to handle EMFILE/ENFILE errors like other system calls. --- blktrace.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/blktrace.c b/blktrace.c index 7d78e13..8e2d47b 100644 --- a/blktrace.c +++ b/blktrace.c @@ -599,6 +599,17 @@ static int my_socket(int domain, int type, int protocol) return fd; } +static int my_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) +{ + int fd; + + do { + fd = accept(sockfd, addr, addrlen); + } while (fd < 0 && handle_open_failure()); + + return fd; +} + static void *my_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { @@ -2133,7 +2144,7 @@ static void net_add_connection(struct net_server_s *ns) struct cl_host *ch; socklen_t socklen = sizeof(ns->addr); - fd = accept(ns->listen_fd, (struct sockaddr *)&ns->addr, &socklen); + fd = my_accept(ns->listen_fd, (struct sockaddr *)&ns->addr, &socklen); if (fd < 0) { /* * This is OK: we just won't accept this connection, -- 2.25.1