From 2b021d21d7d084196560f50f392b1c4962094d99 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Wed, 14 Jul 2010 10:10:10 -0400 Subject: 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. --- erts/epmd/src/epmd_srv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'erts/epmd') diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c index ef471a473a..6b3900fae2 100644 --- a/erts/epmd/src/epmd_srv.c +++ b/erts/epmd/src/epmd_srv.c @@ -157,8 +157,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); -- cgit v1.2.3