From 943f426497451eefd130cc8d7aad51f6b1b3a94d Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Sat, 19 Mar 2011 20:32:52 +0200 Subject: [PATCH] prevent flodding logs when too many open files Simple workaround to prevent Asterisk from going wild when there are too many open files (and also absorbing all the available memory). --- main/asterisk.c | 5 ++++- main/tcptls.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/main/asterisk.c b/main/asterisk.c index 74949151..e2ac81c 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1315,8 +1315,11 @@ static void *listener(void *unused) len = sizeof(sunaddr); s = accept(ast_socket, (struct sockaddr *)&sunaddr, &len); if (s < 0) { - if (errno != EINTR) + if ((errno != EINTR) && (errno != EMFILE)) { ast_log(LOG_WARNING, "Accept returned %d: %s\n", s, strerror(errno)); + } else if (errno == EMFILE) { + ast_log(LOG_ERROR, "Aborting console: too many open files\n"); + } } else { #if !defined(SO_PASSCRED) { diff --git a/main/tcptls.c b/main/tcptls.c index 4f0f08a..443cf59 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -253,7 +253,7 @@ void *ast_tcptls_server_root(void *data) continue; fd = ast_accept(desc->accept_fd, &addr); if (fd < 0) { - if ((errno != EAGAIN) && (errno != EINTR)) + if ((errno != EAGAIN) && (errno != EINTR) && (errno != EMFILE)) ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno)); continue; } -- 1.7.4.1