From 4ff131ff958e2bbe7f1cc8a3d0e0acdd4a48c7ee Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 13 Mar 2021 02:41:41 -0600 Subject: Elliott spotted that errno==EAGAIN usually goes with an rc of -1, not 0. (I hit 0 paired with EAGAIN causing premature pipeline end many years ago when a pipeline was Ctrl-Z then fg, may not still be possible with modern kernels but I left that covered just in case.) --- lib/portability.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/portability.c b/lib/portability.c index 0c364c29..f3c3c251 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -622,12 +622,13 @@ long long sendfile_len(int in, int out, long long bytes, long long *consumed) len = bytes-total; if (bytes<0 || len>sizeof(libbuf)) len = sizeof(libbuf); + errno = 0; #if CFG_TOYBOX_COPYFILERANGE len = copy_file_range(in, 0, out, 0, bytes, 0); #else ww = len = read(in, libbuf, len); #endif - if (!len && errno==EAGAIN) continue; + if (len<1 && errno==EAGAIN) continue; if (len<1) break; if (consumed) *consumed += len; if (ww && writeall(out, libbuf, len) != len) return -1; -- cgit v1.2.3