mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Report error if unable to bind to any socket
When setting up a server socket, we must skip EADDRINUSE errors from bind, since the IPv6 socket bind may have already bound to the IPv4 socket too. If we don't manage to bind to any sockets at all though, we should then report the EADDRINUSE error as normal. This fixes the case where libvirtd would not exit if some other program was listening on its TCP/TLS ports. * src/rpc/virnetsocket.c: Report EADDRINUSE
This commit is contained in:
parent
4bfd0cf700
commit
a44585972a
@ -192,6 +192,7 @@ int virNetSocketNewListenTCP(const char *nodename,
|
|||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int i;
|
int i;
|
||||||
|
int addrInUse = false;
|
||||||
|
|
||||||
*retsocks = NULL;
|
*retsocks = NULL;
|
||||||
*nretsocks = 0;
|
*nretsocks = 0;
|
||||||
@ -250,7 +251,9 @@ int virNetSocketNewListenTCP(const char *nodename,
|
|||||||
virReportSystemError(errno, "%s", _("Unable to bind to port"));
|
virReportSystemError(errno, "%s", _("Unable to bind to port"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
addrInUse = true;
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
runp = runp->ai_next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,6 +276,12 @@ int virNetSocketNewListenTCP(const char *nodename,
|
|||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nsocks == 0 &&
|
||||||
|
addrInUse) {
|
||||||
|
virReportSystemError(EADDRINUSE, "%s", _("Unable to bind to port"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
|
||||||
*retsocks = socks;
|
*retsocks = socks;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user