mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
util: let virSetSockReuseAddr report unified error message
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
37588b2596
commit
1120c06b43
@ -278,10 +278,8 @@ int virNetSocketNewListenTCP(const char *nodename,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virSetSockReuseAddr(fd) < 0) {
|
||||
virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
|
||||
if (virSetSockReuseAddr(fd, true) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
if (runp->ai_family == PF_INET6) {
|
||||
@ -493,9 +491,8 @@ int virNetSocketNewConnectTCP(const char *nodename,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virSetSockReuseAddr(fd) < 0) {
|
||||
if (virSetSockReuseAddr(fd, false) < 0)
|
||||
VIR_WARN("Unable to enable port reuse");
|
||||
}
|
||||
|
||||
if (connect(fd, runp->ai_addr, runp->ai_addrlen) >= 0)
|
||||
break;
|
||||
|
@ -142,11 +142,8 @@ static int virPortAllocatorBindToPort(bool *used,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virSetSockReuseAddr(fd) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("Unable to set socket reuse addr flag"));
|
||||
if (virSetSockReuseAddr(fd, true) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
|
||||
sizeof(v6only)) < 0) {
|
||||
|
@ -148,7 +148,7 @@ int virSetCloseExec(int fd)
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
|
||||
int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED, bool fatal ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/*
|
||||
* SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
|
||||
@ -163,10 +163,17 @@ int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int virSetSockReuseAddr(int fd)
|
||||
int virSetSockReuseAddr(int fd, bool fatal)
|
||||
{
|
||||
int opt = 1;
|
||||
return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||
int ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||
|
||||
if (ret < 0 && fatal) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("Unable to set socket reuse addr flag"));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -43,7 +43,7 @@ int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
||||
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
|
||||
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||
int virSetSockReuseAddr(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||
int virSetSockReuseAddr(int fd, bool fatal) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
int virPipeReadUntilEOF(int outfd, int errfd,
|
||||
char **outbuf, char **errbuf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user