Commit c4d4a918 authored by Mike Hibler's avatar Mike Hibler
Browse files

Don't try so many times (10) to bind to the same port

and return a distinct error when we fail to get the port
parent 7e5633a6
......@@ -1182,7 +1182,7 @@ PlayFrisbee(void)
delay = 0;
if (delay) {
if (debug)
log("Starup delay: %d.%03d seconds",
log("Startup delay: %d.%03d seconds",
delay/1000, delay%1000);
DOSTAT(delayms = delay);
fsleep(delay * 1000);
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2002 University of Utah and the Flux Group.
* Copyright (c) 2000-2002, 2005 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -13,6 +13,7 @@ int ClientLogInit(void);
int ServerLogInit(void);
void log(const char *fmt, ...);
void warning(const char *fmt, ...);
void error(const char *fmt, ...);
void fatal(const char *fmt, ...);
void pwarning(const char *fmt, ...);
void pfatal(const char *fmt, ...);
......@@ -30,7 +30,7 @@ unsigned long nonetbufs;
#endif
/* Max number of times to attempt bind to port before failing. */
#define MAXBINDATTEMPTS 10
#define MAXBINDATTEMPTS 2
/* Max number of hops multicast hops. */
#define MCAST_TTL 5
......@@ -71,8 +71,15 @@ CommonInit(void)
if (bind(sock, (struct sockaddr *)&name, sizeof(name)) == 0)
break;
if (--i == 0)
pfatal("Could not bind to port %d!", portnum);
/*
* Note that we exit with a magic value.
* This is for server wrapper-scripts so that they can
* differentiate this case and try again with a different port.
*/
if (--i == 0) {
error("Could not bind to port %d!\n", portnum);
exit(EADDRINUSE);
}
pwarning("Bind to port %d failed. Will try %d more times!",
portnum, i);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment