Fix another cause of superfluous inotify signals on Android
authorPo Lu <luangruo@yahoo.com>
Fri, 19 Jan 2024 12:51:24 +0000 (20:51 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 19 Jan 2024 12:51:24 +0000 (20:51 +0800)
* src/android.c (android_select): If the event queue isn't
empty upon the initial check, clear all fdsets.

src/android.c

index 757f256c188885959609c8485e45ce053f7c3213..fb7703d84ab02b8bc0f81b829590883eb2a344aa 100644 (file)
@@ -744,6 +744,19 @@ android_select (int nfds, fd_set *readfds, fd_set *writefds,
 
   if (event_queue.num_events)
     {
+      /* Zero READFDS, WRITEFDS and EXCEPTFDS, lest the caller
+        mistakenly interpret this return value as indicating that an
+        inotify file descriptor is readable, and try to poll an
+        unready one.  */
+
+      if (readfds)
+       FD_ZERO (readfds);
+
+      if (writefds)
+       FD_ZERO (writefds);
+
+      if (exceptfds)
+       FD_ZERO (exceptfds);
       pthread_mutex_unlock (&event_queue.mutex);
       return 1;
     }