From e44aa092c5fdcb15f2ae0cfab77c3fc2edc93766 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 15 Dec 2023 23:12:56 +0000 Subject: [PATCH] uevent.c: avoid POLLERR infinite loop I have not reproduced this infinite loop. An infinite loop may be more useful to debug. Note, libhardware_legacy AIDL interface dependency already includes liblog, so this won't change which libraries are loaded. Bug: 300009377 Test: N/A Change-Id: I1f5545456e7074823f0f9df35496cbf5a2a012a4 --- Android.bp | 1 + uevent.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Android.bp b/Android.bp index 409db5d..871b1f9 100644 --- a/Android.bp +++ b/Android.bp @@ -79,6 +79,7 @@ cc_library_shared { shared_libs: [ "android.system.suspend-V1-ndk", "libdl", + "liblog", ], header_libs: [ diff --git a/uevent.c b/uevent.c index e40aa2e..0dcae79 100644 --- a/uevent.c +++ b/uevent.c @@ -16,6 +16,8 @@ #include +#include + #include #include #include @@ -94,6 +96,16 @@ int uevent_next_event(char* buffer, int buffer_length) return count; } } + + if (nr > 0 && (fds.revents & POLLERR)) { + int error = 0; + socklen_t errlen = sizeof(error); + getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &errlen); + + // see b/300009377, this used to be an infinite loop + // abort to try to recover + LOG_ALWAYS_FATAL("Uevent POLLERR: %s, on FD %d", strerror(error), fd); + } } // won't get here