changeset 801519c624e4 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=801519c624e4
description:
base: Fix race condition in the socket listen function
gem5 makes the incorrect assumption that by binding a socket, it
effectively has allocated a port. Linux only allocates ports once you
call
listen on the given socket, not when you call bind. So even if the
port was
free when bind was called, another process (gem5 instance) could race in
between the bind & listen calls and steal the port. In the current
code, if
the call to bind fails due to the port being in use (EADDRINUSE), gem5
retries
for a different port. However if listen fails, gem5 just panics. The
fix is
testing the return value of listen and re-trying if it was due to
EADDRINUSE.
Committed by: Nilay Vaish <[email protected]>
diffstat:
src/base/socket.cc | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diffs (21 lines):
diff -r 1548b7aa657c -r 801519c624e4 src/base/socket.cc
--- a/src/base/socket.cc Tue Jan 28 18:00:50 2014 -0600
+++ b/src/base/socket.cc Tue Jan 28 18:00:51 2014 -0600
@@ -103,11 +103,14 @@
return false;
}
- if (::listen(fd, 1) == -1)
- panic("ListenSocket(listen): listen() failed!");
+ if (::listen(fd, 1) == -1) {
+ if (errno != EADDRINUSE)
+ panic("ListenSocket(listen): listen() failed!");
+
+ return false;
+ }
listening = true;
-
anyListening = true;
return true;
}
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev