From: Tobias Brunner Date: Fri, 1 Mar 2013 16:01:21 +0000 (+0100) Subject: android: Mitigate race condition on reauthentication X-Git-Tag: 5.0.3dr3~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e88b529a30a4b8d31c7754645bda1f1edb1b4e45;p=thirdparty%2Fstrongswan.git 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. --- diff --git a/src/frontends/android/jni/libandroidbridge/backend/android_service.c b/src/frontends/android/jni/libandroidbridge/backend/android_service.c index 2f13be93c7..c83f0b4dce 100644 --- a/src/frontends/android/jni/libandroidbridge/backend/android_service.c +++ b/src/frontends/android/jni/libandroidbridge/backend/android_service.c @@ -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; }