android: Mitigate race condition on reauthentication
If the TUN device gets recreated while another thread in handle_plain() has not yet called select(2) but already stored the file descriptor of the old TUN device in its FD set, select() will fail with EBADF. Fixes #301.
This commit is contained in:
@@ -167,6 +167,10 @@ static job_requeue_t handle_plain(private_android_service_t *this)
|
|||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
{
|
||||||
|
if (errno == EBADF)
|
||||||
|
{ /* the TUN device got closed just before calling select(), retry */
|
||||||
|
return JOB_REQUEUE_FAIR;
|
||||||
|
}
|
||||||
DBG1(DBG_DMN, "select on TUN device failed: %s", strerror(errno));
|
DBG1(DBG_DMN, "select on TUN device failed: %s", strerror(errno));
|
||||||
return JOB_REQUEUE_NONE;
|
return JOB_REQUEUE_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user