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:
Tobias Brunner 2013-03-01 17:01:21 +01:00
parent 4c969f7906
commit e88b529a30
1 changed files with 4 additions and 0 deletions

View File

@ -167,6 +167,10 @@ static job_requeue_t handle_plain(private_android_service_t *this)
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));
return JOB_REQUEUE_NONE;
}