Pull IO 2017/11/06 v2
-----BEGIN PGP SIGNATURE----- iQIcBAABCAAGBQJaAcStAAoJEL6G67QVEE/fWU8QAIG1s9gMe4NOqN5hqX7BxLgf EBqQxzu2kE61Flq2NhgKh9EWdnb2q4Ig6p1etz1m2a0BAV6KayeFEi3iJq2+bCq7 odZgmXNmGBlBj2YbdBFy4E1ku5pr6ZmUHKE4ukHJs2ODm0eGFiQNnPIohXaXVltj 4F2PrC9rcfhB3kiMPZO5Ak+D4cDj+m0WP2aZw1PHzZKAefIHEIIksSPsKXRu5jBk mw6nKB9g3B99UR/txd8BF73FEAaVEVy6ExAJK4cbU8t7t7vtYmotYdn0KOYqxBhM ZCWz2v+/RkX5vJSBWHRkxjF0vRqQSGlemZ8ov9pUk9nYa1xi9vyJ/LIFkh2YmoGv 3n/jLzq1X4e/tA5d9RuwHiHO45sKlQBYs7z6h8D+exZO22F6BY2of2mp96VXayzD bGKT94Bpcb32YUUeuCLfSQBjXK0jUPEot1+JHLINkVH+iIau9v0/VHrTslGq32RI Y02aGU5bUkGZpzoBG4kw7FCH8S3odzFW5DY3Dzl0km3h2qX+dbv+yeQEhVGuIv1d 2j9WRm8YkmvS+YWmfHFMbe7Kaf/PGORT0Z5lxu2g5DRI24azynCS4BswrOtvhJ61 YFA+8/w6s3WLCQeCP56V9BLJOLUGTK2XX/e2xjM7Wg8kf0v3xpdCoD+lZy7mrJ5f CSXL9PFs0Z0ORZvAs/fN =6Ty4 -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/berrange/tags/pull-2017-11-06-2' into staging Pull IO 2017/11/06 v2 # gpg: Signature made Tue 07 Nov 2017 14:35:25 GMT # gpg: using RSA key 0xBE86EBB415104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" # Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF * remotes/berrange/tags/pull-2017-11-06-2: sockets: avoid leak of listen file descriptor Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
5ca7a3cba4
@ -207,7 +207,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
||||
char uaddr[INET6_ADDRSTRLEN+1];
|
||||
char uport[33];
|
||||
int rc, port_min, port_max, p;
|
||||
int slisten = 0;
|
||||
int slisten = -1;
|
||||
int saved_errno = 0;
|
||||
bool socket_created = false;
|
||||
Error *err = NULL;
|
||||
@ -267,31 +267,42 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
||||
uaddr,INET6_ADDRSTRLEN,uport,32,
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
slisten = create_fast_reuse_socket(e);
|
||||
if (slisten < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
socket_created = true;
|
||||
port_min = inet_getport(e);
|
||||
port_max = saddr->has_to ? saddr->to + port_offset : port_min;
|
||||
for (p = port_min; p <= port_max; p++) {
|
||||
inet_setport(e, p);
|
||||
rc = try_bind(slisten, saddr, e);
|
||||
if (rc) {
|
||||
if (errno == EADDRINUSE) {
|
||||
|
||||
slisten = create_fast_reuse_socket(e);
|
||||
if (slisten < 0) {
|
||||
/* First time we expect we might fail to create the socket
|
||||
* eg if 'e' has AF_INET6 but ipv6 kmod is not loaded.
|
||||
* Later iterations should always succeed if first iteration
|
||||
* worked though, so treat that as fatal.
|
||||
*/
|
||||
if (p == port_min) {
|
||||
continue;
|
||||
} else {
|
||||
error_setg_errno(errp, errno, "Failed to bind socket");
|
||||
error_setg_errno(errp, errno,
|
||||
"Failed to recreate failed listening socket");
|
||||
goto listen_failed;
|
||||
}
|
||||
}
|
||||
if (!listen(slisten, 1)) {
|
||||
goto listen_ok;
|
||||
}
|
||||
if (errno != EADDRINUSE) {
|
||||
error_setg_errno(errp, errno, "Failed to listen on socket");
|
||||
goto listen_failed;
|
||||
socket_created = true;
|
||||
|
||||
rc = try_bind(slisten, saddr, e);
|
||||
if (rc < 0) {
|
||||
if (errno != EADDRINUSE) {
|
||||
error_setg_errno(errp, errno, "Failed to bind socket");
|
||||
goto listen_failed;
|
||||
}
|
||||
} else {
|
||||
if (!listen(slisten, 1)) {
|
||||
goto listen_ok;
|
||||
}
|
||||
if (errno != EADDRINUSE) {
|
||||
error_setg_errno(errp, errno, "Failed to listen on socket");
|
||||
goto listen_failed;
|
||||
}
|
||||
}
|
||||
/* Someone else managed to bind to the same port and beat us
|
||||
* to listen on it! Socket semantics does not allow us to
|
||||
@ -299,12 +310,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
||||
* socket to allow bind attempts for subsequent ports:
|
||||
*/
|
||||
closesocket(slisten);
|
||||
slisten = create_fast_reuse_socket(e);
|
||||
if (slisten < 0) {
|
||||
error_setg_errno(errp, errno,
|
||||
"Failed to recreate failed listening socket");
|
||||
goto listen_failed;
|
||||
}
|
||||
slisten = -1;
|
||||
}
|
||||
}
|
||||
error_setg_errno(errp, errno,
|
||||
|
Loading…
Reference in New Issue
Block a user