mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
client: Report proper close reason
When we get a POLLHUP or VIR_EVENT_HANDLE_HANGUP event for a client, we still want to read from the socket to process any accumulated data. But doing so inevitably results in an error and a call to virNetClientMarkClose before we get to processing the hangup event (and another call to virNetClientMarkClose). However the close reason passed to the second virNetClientMarkClose call is ignored because another one was already set. We need to pass the correct close reason when marking the socket to be closed for the first time. https://bugzilla.redhat.com/show_bug.cgi?id=1373859 Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
59307fade8
commit
42faf316ec
@ -1595,6 +1595,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
{
|
{
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
int closeReason;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fds[0].fd = virNetSocketGetFD(client->sock);
|
fds[0].fd = virNetSocketGetFD(client->sock);
|
||||||
@ -1703,9 +1704,14 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fds[0].revents & POLLHUP)
|
||||||
|
closeReason = VIR_CONNECT_CLOSE_REASON_EOF;
|
||||||
|
else
|
||||||
|
closeReason = VIR_CONNECT_CLOSE_REASON_ERROR;
|
||||||
|
|
||||||
if (fds[0].revents & POLLOUT) {
|
if (fds[0].revents & POLLOUT) {
|
||||||
if (virNetClientIOHandleOutput(client) < 0) {
|
if (virNetClientIOHandleOutput(client) < 0) {
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
|
virNetClientMarkClose(client, closeReason);
|
||||||
error = true;
|
error = true;
|
||||||
/* Fall through to process any pending data. */
|
/* Fall through to process any pending data. */
|
||||||
}
|
}
|
||||||
@ -1713,7 +1719,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
|
|
||||||
if (fds[0].revents & POLLIN) {
|
if (fds[0].revents & POLLIN) {
|
||||||
if (virNetClientIOHandleInput(client) < 0) {
|
if (virNetClientIOHandleInput(client) < 0) {
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
|
virNetClientMarkClose(client, closeReason);
|
||||||
error = true;
|
error = true;
|
||||||
/* Fall through to process any pending data. */
|
/* Fall through to process any pending data. */
|
||||||
}
|
}
|
||||||
@ -1746,13 +1752,13 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
if (fds[0].revents & POLLHUP) {
|
if (fds[0].revents & POLLHUP) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("received hangup event on socket"));
|
_("received hangup event on socket"));
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_EOF);
|
virNetClientMarkClose(client, closeReason);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (fds[0].revents & POLLERR) {
|
if (fds[0].revents & POLLERR) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("received error event on socket"));
|
_("received error event on socket"));
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
|
virNetClientMarkClose(client, closeReason);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1968,6 +1974,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
|
|||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virNetClientPtr client = opaque;
|
virNetClientPtr client = opaque;
|
||||||
|
int closeReason;
|
||||||
|
|
||||||
virObjectLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
@ -1981,23 +1988,25 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
|
|||||||
|
|
||||||
VIR_DEBUG("Event fired %p %d", sock, events);
|
VIR_DEBUG("Event fired %p %d", sock, events);
|
||||||
|
|
||||||
|
if (events & VIR_EVENT_HANDLE_HANGUP)
|
||||||
|
closeReason = VIR_CONNECT_CLOSE_REASON_EOF;
|
||||||
|
else
|
||||||
|
closeReason = VIR_CONNECT_CLOSE_REASON_ERROR;
|
||||||
|
|
||||||
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
||||||
if (virNetClientIOHandleOutput(client) < 0)
|
if (virNetClientIOHandleOutput(client) < 0)
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
|
virNetClientMarkClose(client, closeReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & VIR_EVENT_HANDLE_READABLE) {
|
if (events & VIR_EVENT_HANDLE_READABLE) {
|
||||||
if (virNetClientIOHandleInput(client) < 0)
|
if (virNetClientIOHandleInput(client) < 0)
|
||||||
virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
|
virNetClientMarkClose(client, closeReason);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR)) {
|
if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR)) {
|
||||||
VIR_DEBUG("VIR_EVENT_HANDLE_HANGUP or "
|
VIR_DEBUG("VIR_EVENT_HANDLE_HANGUP or "
|
||||||
"VIR_EVENT_HANDLE_ERROR encountered");
|
"VIR_EVENT_HANDLE_ERROR encountered");
|
||||||
virNetClientMarkClose(client,
|
virNetClientMarkClose(client, closeReason);
|
||||||
(events & VIR_EVENT_HANDLE_HANGUP) ?
|
|
||||||
VIR_CONNECT_CLOSE_REASON_EOF :
|
|
||||||
VIR_CONNECT_CLOSE_REASON_ERROR);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user