[PATCH] Exit if an error occurs with the listening socket

Michael Santos michael.santos@REDACTED
Sun Mar 21 02:30:32 CET 2010


Check errno if either select() or accept() returns an error and exit.
This prevents epmd from looping and taking up 100% CPU.
---
 erts/epmd/src/epmd_srv.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c
index a033fab..7e4a661 100644
--- a/erts/epmd/src/epmd_srv.c
+++ b/erts/epmd/src/epmd_srv.c
@@ -227,8 +227,16 @@ void run(EpmdVars *g)
       timeout.tv_sec = (g->packet_timeout < IDLE_TIMEOUT) ? 1 : IDLE_TIMEOUT;
       timeout.tv_usec = 0;
 
-      if ((ret = select(g->max_conn,&read_mask,(fd_set *)0,(fd_set *)0,&timeout)) < 0)
+      if ((ret = select(g->max_conn,&read_mask,(fd_set *)0,(fd_set *)0,&timeout)) < 0) {
 	dbg_perror(g,"error in select ");
+        switch (errno) {
+          case EAGAIN:
+          case EINTR:
+            break;
+          default:
+            epmd_cleanup_exit(g,1);
+        }
+      }
       else {
 	time_t now;
 	if (ret == 0) {
@@ -401,7 +409,14 @@ static int do_accept(EpmdVars *g,int listensock)
 
     if (msgsock < 0) {
         dbg_perror(g,"error in accept");
-	return EPMD_FALSE;
+        switch (errno) {
+            case EAGAIN:
+            case ECONNABORTED:
+            case EINTR:
+	            return EPMD_FALSE;
+            default:
+	            epmd_cleanup_exit(g,1);
+        }
     }
 
     return conn_open(g,msgsock);
-- 
1.5.4.3



More information about the erlang-patches mailing list