Permalink
Browse files

check return value of epmd server listen() call

The listen() call can fail due to a variety of conditions, so check
its return value and if it fails, print a suitable debug message if
appropriate and then exit. The exit values used are the same for those
already used for bind() failures: 0 if the error is EADDRINUSE, 1
otherwise.
  • Loading branch information...
1 parent c4b4eda commit c5c8baa686b2cd5c43ecbf40fbb47d04f200b552 @vinoski committed Jul 14, 2010
Showing with 14 additions and 2 deletions.
  1. +14 −2 erts/epmd/src/epmd_srv.c
View
@@ -188,8 +188,20 @@ void run(EpmdVars *g)
dbg_printf(g,2,"starting");
- listen(listensock, SOMAXCONN);
-
+ if(listen(listensock, SOMAXCONN) < 0)
+ {
+ if (errno == EADDRINUSE)
+ {
+ dbg_tty_printf(g,1,"there is already a epmd running at port %d",
+ g->port);
+ epmd_cleanup_exit(g,0);
+ }
+ else
+ {
+ dbg_perror(g,"failed to listen on socket");
+ epmd_cleanup_exit(g,1);
+ }
+ }
FD_ZERO(&g->orig_read_mask);
FD_SET(listensock,&g->orig_read_mask);

0 comments on commit c5c8baa

Please sign in to comment.