mirror of https://gitee.com/openkylin/libvirt.git
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;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetSockReuseAddr(fd) < 0) {
|
if (virSetSockReuseAddr(fd, true) < 0)
|
||||||
virReportSystemError(errno, "%s", _("Unable to enable port reuse"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef IPV6_V6ONLY
|
#ifdef IPV6_V6ONLY
|
||||||
if (runp->ai_family == PF_INET6) {
|
if (runp->ai_family == PF_INET6) {
|
||||||
|
@ -493,9 +491,8 @@ int virNetSocketNewConnectTCP(const char *nodename,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetSockReuseAddr(fd) < 0) {
|
if (virSetSockReuseAddr(fd, false) < 0)
|
||||||
VIR_WARN("Unable to enable port reuse");
|
VIR_WARN("Unable to enable port reuse");
|
||||||
}
|
|
||||||
|
|
||||||
if (connect(fd, runp->ai_addr, runp->ai_addrlen) >= 0)
|
if (connect(fd, runp->ai_addr, runp->ai_addrlen) >= 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -142,11 +142,8 @@ static int virPortAllocatorBindToPort(bool *used,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetSockReuseAddr(fd) < 0) {
|
if (virSetSockReuseAddr(fd, true) < 0)
|
||||||
virReportSystemError(errno, "%s",
|
|
||||||
_("Unable to set socket reuse addr flag"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
|
if (ipv6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only,
|
||||||
sizeof(v6only)) < 0) {
|
sizeof(v6only)) < 0) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ int virSetCloseExec(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#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
|
* SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
|
||||||
|
@ -163,10 +163,17 @@ int virSetSockReuseAddr(int fd ATTRIBUTE_UNUSED)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int virSetSockReuseAddr(int fd)
|
int virSetSockReuseAddr(int fd, bool fatal)
|
||||||
{
|
{
|
||||||
int opt = 1;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
|
int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetCloseExec(int fd) 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,
|
int virPipeReadUntilEOF(int outfd, int errfd,
|
||||||
char **outbuf, char **errbuf);
|
char **outbuf, char **errbuf);
|
||||||
|
|
Loading…
Reference in New Issue