Hi,

On 30/06/2025 13:37, Ron Yorston wrote:
@@ -219,6 +219,10 @@ shell_builtin_read(struct builtin_read_params *params)
                if (poll(pfd, 1, timeout) <= 0) {
                        /* timed out, or EINTR */

The comment here is wrong, this can (rarely) fail for other reasons than timeout or EINTR, so...

                        err = errno;
+                       if (err != EINTR) {

...this should check if (!err) to ensure that truly only timeouts result in a return value of 2.

An incredibly contrived test case with your patch applied:

  $ time ./busybox sh -c 'ulimit -n 0; read -t 10'; echo $?

  real    0m0.007s
  user    0m0.000s
  sys     0m0.000s
  142

That is, this exited immediately because poll() failed with EINVAL, but the return value indicates that this timed out.

With the change I am suggesting here, this exits with status 1 instead.

Alternatively, poll()'s result could be used instead rather than errno to distinguish between error and timeout.

Other than that, it looks like a good change to me!

Cheers,
Harald van Dijk
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to