diff mbox series

[u-boot-marvell,12/14] tools: kwboot: Handle EINTR in kwboot_tty_recv()

Message ID 20220125171313.14498-13-kabel@kernel.org
State Accepted
Commit 91fb095c0dc8390bee2442e7b635e2a93bb31c4a
Delegated to: Stefan Roese
Headers show
Series Another set of kwboot improvements | expand

Commit Message

Marek Behún Jan. 25, 2022, 5:13 p.m. UTC
From: Pali Rohár <pali@kernel.org>

The select() and read() syscalls may be interrupted. Handle EINTR and
retry them.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 tools/kwboot.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Stefan Roese Jan. 26, 2022, 3:41 p.m. UTC | #1
On 1/25/22 18:13, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> The select() and read() syscalls may be interrupted. Handle EINTR and
> retry them.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan


> ---
>   tools/kwboot.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index 8b748f0fdd..fca1c73c55 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -409,15 +409,19 @@ kwboot_tty_recv(int fd, void *buf, size_t len, int timeo)
>   
>   	do {
>   		nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
> -		if (nfds < 0)
> +		if (nfds < 0 && errno == EINTR)
> +			continue;
> +		else if (nfds < 0)
>   			goto out;
> -		if (!nfds) {
> +		else if (!nfds) {
>   			errno = ETIMEDOUT;
>   			goto out;
>   		}
>   
>   		n = read(fd, buf, len);
> -		if (n <= 0)
> +		if (n < 0 && errno == EINTR)
> +			continue;
> +		else if (n <= 0)
>   			goto out;
>   
>   		buf = (char *)buf + n;

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 8b748f0fdd..fca1c73c55 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -409,15 +409,19 @@  kwboot_tty_recv(int fd, void *buf, size_t len, int timeo)
 
 	do {
 		nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
-		if (nfds < 0)
+		if (nfds < 0 && errno == EINTR)
+			continue;
+		else if (nfds < 0)
 			goto out;
-		if (!nfds) {
+		else if (!nfds) {
 			errno = ETIMEDOUT;
 			goto out;
 		}
 
 		n = read(fd, buf, len);
-		if (n <= 0)
+		if (n < 0 && errno == EINTR)
+			continue;
+		else if (n <= 0)
 			goto out;
 
 		buf = (char *)buf + n;