Improve the error handling in passive TFO test to check the return value
from sendto(), and to fail if read() or fprintf() failed.
Signed-off-by: Yohei Kojima <yk@y-koj.net>
---
tools/testing/selftests/net/tfo.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/tfo.c b/tools/testing/selftests/net/tfo.c
index 8d82140f0f76..3b1ee2d3d417 100644
--- a/tools/testing/selftests/net/tfo.c
+++ b/tools/testing/selftests/net/tfo.c
@@ -82,8 +82,10 @@ static void run_server(void)
error(1, errno, "getsockopt(SO_INCOMING_NAPI_ID)");
if (read(connfd, buf, 64) < 0)
- perror("read()");
- fprintf(outfile, "%d\n", opt);
+ error(1, errno, "read()");
+
+ if (fprintf(outfile, "%d\n", opt) < 0)
+ error(1, errno, "fprintf()");
fclose(outfile);
close(connfd);
@@ -92,14 +94,17 @@ static void run_server(void)
static void run_client(void)
{
- int fd;
+ int fd, ret;
char *msg = "Hello, world!";
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd == -1)
error(1, errno, "socket()");
- sendto(fd, msg, strlen(msg), MSG_FASTOPEN, (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+ ret = sendto(fd, msg, strlen(msg), MSG_FASTOPEN,
+ (struct sockaddr *)&cfg_addr, sizeof(cfg_addr));
+ if (ret < 0)
+ error(1, errno, "sendto()");
close(fd);
}
--
2.52.0
> Improve the error handling in passive TFO test to check the return value > from sendto(), and to fail if read() or fprintf() failed. You propose to adjust error detection and corresponding exception handling another bit. How do you think about to take also another look if further function implementations would be similarly affected? Regards, Markus
On Wed, Jan 14, 2026 at 09:33:12AM +0100, Markus Elfring wrote: > > Improve the error handling in passive TFO test to check the return value > > from sendto(), and to fail if read() or fprintf() failed. > > You propose to adjust error detection and corresponding exception handling another bit. > How do you think about to take also another look if further function implementations > would be similarly affected? Thank you for the suggestion. The first objective of this series is to fix the misleading behavior that was caused by the following bug. Therefore, I intentionally limited the scope of this patch to the affected or closely related functions. https://lore.kernel.org/netdev/602c9e1ba5bb2ee1997bb38b1d866c9c3b807ae9.1767624906.git.yk@y-koj.net/ I believe this is sufficient to prevent it from showing misleading error messages when the test fails. Thank you, Yohei > > Regards, > Markus
…
> +++ b/tools/testing/selftests/net/tfo.c
> @@ -82,8 +82,10 @@ static void run_server(void)
…
> if (read(connfd, buf, 64) < 0)
> - perror("read()");
> - fprintf(outfile, "%d\n", opt);
> + error(1, errno, "read()");
> +
> + if (fprintf(outfile, "%d\n", opt) < 0)
> + error(1, errno, "fprintf()");
>
> fclose(outfile);
> close(connfd);
…
Why was error detection omitted for close() calls here so far?
https://pubs.opengroup.org/onlinepubs/9799919799/functions/fclose.html
Regards,
Markus
On Tue, Jan 13, 2026 at 03:48:11PM +0100, Markus Elfring wrote:
> …
> > +++ b/tools/testing/selftests/net/tfo.c
> > @@ -82,8 +82,10 @@ static void run_server(void)
> …
> > if (read(connfd, buf, 64) < 0)
> > - perror("read()");
> > - fprintf(outfile, "%d\n", opt);
> > + error(1, errno, "read()");
> > +
> > + if (fprintf(outfile, "%d\n", opt) < 0)
> > + error(1, errno, "fprintf()");
> >
> > fclose(outfile);
> > close(connfd);
> …
>
> Why was error detection omitted for close() calls here so far?
Because I believe that checking the return value of fclose() would not
provide additional value in this test case, which is focused on testing
the behavior of passive TFO.
I understand that fclose() could fail there, but considering the
trade-off between test reliability and code complexity (which increases
review and maintenance costs), I think checking the return value there
does not provide benefits to justify the added complexity. In fact, as
far as I can see, none of the existing tests in selftests/net check the
fclose() return value.
Thank you,
Yohei
>
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/fclose.html
>
> Regards,
> Markus
© 2016 - 2026 Red Hat, Inc.