vsock/test: fix send_buf()/recv_buf() EINTR handling
Subsystems (4)
Stefano Garzarella
maintainerPATCH 1/1 vsock/test: fix send_buf()/recv_buf() EINTR handling
From: Stefano Garzarella <[email protected]>
When send() or recv() returns -1 with errno == EINTR, the code skips the break but still adds the return value to nwritten/nread, making it decrease by 1. This leads to wrong buffer offsets and wrong bytes count.
Fix it by explicitly continuing the loop on EINTR, so the return value is only added when it is positive.
--- tools/testing/vsock/util.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/vsock/util.c +6 -2
@@ -344,7 +344,9 @@ void send_buf(int fd, const void *buf, size_t len, int flags, ret =send (fd, buf + nwritten, len - nwritten, flags);timeout_check ("send" ); -if (ret ==0 || (ret <0 && errno !=EINTR )) +if (ret <0 && errno ==EINTR ) +continue ; +if (ret <=0 )break ; nwritten += ret;
@@ -396,7 +398,9 @@ void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_ret) ret =recv (fd, buf + nread, len - nread, flags);timeout_check ("recv" ); -if (ret ==0 || (ret <0 && errno !=EINTR )) +if (ret <0 && errno ==EINTR ) +continue ; +if (ret <=0 )break ; nread += ret;
Signature · 1 line
2.53.0
Quoted 45 lines · Stefano Garzarella
From: Stefano Garzarella <[email protected]>
When
send()orrecv()returns -1 with errno == EINTR, the code skips the break but still adds the return value to nwritten/nread, making it decrease by 1. This leads to wrong buffer offsets and wrong bytes count.Fix it by explicitly continuing the loop on EINTR, so the return value is only added when it is positive.
Fixes a8ed71a27ef5 ("vsock/test: add recv_buf() utility function")Fixes 12329bd51fdc ("vsock/test: add send_buf() utility function")Signed-off-by Stefano Garzarella <[email protected]>---
tools/testing/vsock/util.c| 8 ++++++--1 file changed, 6 insertions(+), 2 deletions(-)tools/testing/vsock/util.c +6
-2@@ -344,7 +344,9 @@ void send_buf(int fd, const void *buf, size_t len, int flags, ret =send (fd, buf + nwritten, len - nwritten, flags);timeout_check ("send" ); -if (ret ==0 || (ret <0 && errno !=EINTR )) +if (ret <0 && errno ==EINTR ) +continue ; +if (ret <=0 )break ; nwritten += ret;@@ -396,7 +398,9 @@ void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_ret) ret =recv (fd, buf + nread, len - nread, flags);timeout_check ("recv" ); -if (ret ==0 || (ret <0 && errno !=EINTR )) +if (ret <0 && errno ==EINTR ) +continue ; +if (ret <=0 )break ; nread += ret;Signature · 1 line
2.53.0
LGTM!
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 3 Apr 2026 11:32:51 +0200 you wrote:
From: Stefano Garzarella <[email protected]>
When
send()orrecv()returns -1 with errno == EINTR, the code skips the break but still adds the return value to nwritten/nread, making it decrease by 1. This leads to wrong buffer offsets and wrong bytes count.Fix it by explicitly continuing the loop on EINTR, so the return value is only added when it is positive.
[...]
Here is the summary with links:
- [net] vsock/test: fix send_buf()/recv_buf() EINTR handling
https://git.kernel.org/netdev/net/c/24ad7ff66889
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html