[PATCH] wmacpi: fix musl libc incompatibility in event loop

3 views
Skip to first unread message

david.m...@gmail.com

unread,
Mar 29, 2026, 10:37:08 AM (8 days ago) Mar 29
to Window Maker Development
This patch makes the code to not rely on select() mutating tv,
but only uses its return value, as POSIX leaves it unspecified
whether select() updates the timeval.
glibc historically modifies tv to the remaining timeout while
musl follows POSIX strictly and does not touch tv.
---
 wmacpi/wmacpi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/wmacpi/wmacpi.c b/wmacpi/wmacpi.c
index b6ec6c3..bc49fb9 100644
--- a/wmacpi/wmacpi.c
+++ b/wmacpi/wmacpi.c
@@ -681,6 +681,7 @@ int main(int argc, char **argv)
     fd_set fds;
     struct timeval tv_rate;
     struct timeval tv = {0, 0};
+    int select_ret = 0;
 
     DAProgramOption options[] = {
      {"-r", "--no-scroll", "disable scrolling message", DONone, False, {NULL}},
@@ -894,12 +895,12 @@ int main(int argc, char **argv)
   * frequently than we sample (most likely). In that case we
   * set the timeout based on the display update cycle. */
 
- /* have we completed our timeout, or were we woken up early? */
- if ((tv.tv_sec != 0) || (tv.tv_usec != 0))
+ /* Have we completed our timeout, or were we woken up early?
+  * Use select()'s return value: >0 means a fd became ready (X event),
+  * 0 means timeout. */
+ if (select_ret > 0)
      goto win_update;
 
- tv = tv_rate;
-
  sample_count += dockapp->period_length;
 
  if (sample_count >= samplerate) {
@@ -970,7 +971,8 @@ int main(int argc, char **argv)
 
  FD_ZERO(&fds);
  FD_SET(dockapp->x_fd, &fds);
- select(FD_SETSIZE, &fds, NULL, NULL, &tv);
+ tv = tv_rate;
+ select_ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
     }
     return 0;
 }
--
2.43.0
0001-wmacpi-fix-musl-libc-incompatibility-in-event-loop.patch
Reply all
Reply to author
Forward
0 new messages