From 3117c15fbd5e2ca86c3ac042e03f56b09202316a Mon Sep 17 00:00:00 2001 From: Yves Rutschle Date: Thu, 11 Jan 2024 21:32:39 +0100 Subject: [PATCH] when sslh-fork accept() fails with some errors, retry accept instead of dying --- sslh-fork.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sslh-fork.c b/sslh-fork.c index 139338a..74335d7 100644 --- a/sslh-fork.c +++ b/sslh-fork.c @@ -178,6 +178,25 @@ void tcp_listener(struct listen_endpoint* endpoint, int num_endpoints, int activ while (1) { in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0); CHECK_RES_RETURN(in_socket, "accept", /*void*/ ); + if (in_socket == -1) { + print_message(msg_system_error, "%s:%d:%s:%d:%s\n", + __FILE__, __LINE__, "accept", errno, strerror(errno)); + switch(in_socket) { + case ENETDOWN: /* accept(2) cites all these errnos as "you should retry" */ + case EPROTO: + case ENOPROTOOPT: + case EHOSTDOWN: + case ENONET: + case EHOSTUNREACH: + case EOPNOTSUPP: + case ENETUNREACH: + case ECONNABORTED: + continue; + + default: /* Otherwise, it's something wrong in our parameters, we fail */ + return; + } + } print_message(msg_fd, "accepted fd %d\n", in_socket); switch(fork()) {