]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
fix select() timeout conversion — was passing raw pointer as kernel timeout
authorTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 21:30:12 +0000 (18:30 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 21:30:12 +0000 (18:30 -0300)
commitd1c7dc7411f0de2e228526b73f83ed2f0a1df5e8
tree49f0cbb9d735f03fa3600f744ab449743ba1976b
parenta1771488db7a7e3b587e93ca661b7128fbfaa07e
fix select() timeout conversion — was passing raw pointer as kernel timeout

The select() wrapper in both newlib/posix_stubs.c and ulibc/unistd.c
was casting the struct timeval* pointer directly to int and passing it
as the 5th syscall argument. The kernel expects an int32_t timeout:
  -1 = infinite wait, 0 = poll (return immediately), >0 = ticks.

When bash calls select() with timeout=NULL (infinite wait), the raw
pointer value was interpreted as a large positive number (poll with
timeout), not as -1 (infinite). Worse, on some code paths the pointer
could be 0 (NULL), which the kernel treats as timeout=0 (poll only),
causing select() to return 0 immediately with no fds ready — which
bash interprets as EOF on stdin, causing it to exit immediately.

Fix: convert struct timeval to int32_t ticks before passing to the
kernel. NULL timeout → -1 (infinite). tv_sec=0, tv_usec=0 → 0 (poll).
Otherwise convert ms → ticks (TIMER_HZ=100, 10ms/tick).
newlib/libgloss/adros/posix_stubs.c
user/ulibc/src/unistd.c