Check the stdin poll() return value before reading

This commit is contained in:
Cameron Gutman 2016-01-05 19:53:23 -06:00
parent dc254e1ee5
commit 006ad72eb2

View File

@ -295,6 +295,8 @@ int main(int argc, char* argv[]) {
}
while (pollres == 0);
if (pollres > 0 && (pollinfo.revents & POLLIN)) {
// We'll have data available now
ret = fread(&requestId, sizeof(requestId), 1, stdin);
if (ret < sizeof(requestId)) {
__android_log_print(ANDROID_LOG_ERROR, "EvdevReader", "Short read on input");
@ -324,4 +326,18 @@ int main(int argc, char* argv[]) {
pthread_mutex_unlock(&DeviceListLock);
}
}
else {
// Terminate this thread
if (pollres < 0) {
__android_log_print(ANDROID_LOG_ERROR, "EvdevReader",
"Stdin poll() failed: %d", errno);
}
else {
__android_log_print(ANDROID_LOG_ERROR, "EvdevReader",
"Stdin unexpected revents: %d", pollinfo.revents);
}
return -1;
}
}
}