Properly store errno on listener epoll errors

When an epoll error occurs for a listener, the errno variable must be
stored in another variable while the listener is removed from all of the
epoll instances.
This commit is contained in:
Markus Makela
2016-11-25 18:28:06 +02:00
parent bfc60ae940
commit bcbff604b0

View File

@ -387,6 +387,8 @@ poll_add_dcb(DCB *dcb)
dcb_add_to_list(dcb); dcb_add_to_list(dcb);
int error_num = 0;
if (dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER) if (dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER)
{ {
/** Listeners are added to all epoll instances */ /** Listeners are added to all epoll instances */
@ -396,6 +398,7 @@ poll_add_dcb(DCB *dcb)
{ {
if ((rc = epoll_ctl(epoll_fd[i], EPOLL_CTL_ADD, dcb->fd, &ev))) if ((rc = epoll_ctl(epoll_fd[i], EPOLL_CTL_ADD, dcb->fd, &ev)))
{ {
error_num = errno;
/** Remove the listener from the previous epoll instances */ /** Remove the listener from the previous epoll instances */
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
{ {
@ -407,13 +410,16 @@ poll_add_dcb(DCB *dcb)
} }
else else
{ {
rc = epoll_ctl(epoll_fd[owner], EPOLL_CTL_ADD, dcb->fd, &ev); if ((rc = epoll_ctl(epoll_fd[owner], EPOLL_CTL_ADD, dcb->fd, &ev)))
{
error_num = errno;
}
} }
if (rc) if (rc)
{ {
/* Some errors are actually considered acceptable */ /* Some errors are actually considered acceptable */
rc = poll_resolve_error(dcb, errno, true); rc = poll_resolve_error(dcb, error_num, true);
} }
if (0 == rc) if (0 == rc)
{ {
@ -477,6 +483,8 @@ poll_remove_dcb(DCB *dcb)
if (dcbfd > 0) if (dcbfd > 0)
{ {
int error_num = 0;
if (dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER) if (dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER)
{ {
/** Listeners are added to all epoll instances */ /** Listeners are added to all epoll instances */
@ -490,12 +498,16 @@ poll_remove_dcb(DCB *dcb)
/** Even if one of the instances failed to remove it, try /** Even if one of the instances failed to remove it, try
* to remove it from all the others */ * to remove it from all the others */
rc = tmp_rc; rc = tmp_rc;
error_num = errno;
} }
} }
} }
else else
{ {
rc = epoll_ctl(epoll_fd[dcb->thread.id], EPOLL_CTL_DEL, dcbfd, &ev); if ((rc = epoll_ctl(epoll_fd[dcb->thread.id], EPOLL_CTL_DEL, dcbfd, &ev)))
{
error_num = errno;
}
} }
/** /**
* The poll_resolve_error function will always * The poll_resolve_error function will always
@ -504,7 +516,7 @@ poll_remove_dcb(DCB *dcb)
*/ */
if (rc) if (rc)
{ {
rc = poll_resolve_error(dcb, errno, false); rc = poll_resolve_error(dcb, error_num, false);
} }
if (rc) if (rc)
{ {