[LTP] [PATCH] safe_macros: Fix confusing safe_read() failure output
Cyril Hrubis
chrubis@suse.cz
Thu Jan 9 16:03:36 CET 2025
In the case that we read() less bytes than expected in the strict mode
we used the same tst_brk() as for the case when read() fails. However
for short reads the errno is in an udefined state and we possibly end up
with confusing TBROK message. Andrea reported EACESS ernno in the TBROK
message on a short read() while developing tests.
Reported-by: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
lib/safe_macros.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 109268587..b224a5861 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -293,7 +293,7 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
rval = read(fildes, buf, nbyte);
- if (rval == -1 || (len_strict && (size_t)rval != nbyte)) {
+ if (rval == -1) {
tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
"read(%d,%p,%zu) failed, returned %zd", fildes, buf,
nbyte, rval);
@@ -301,6 +301,10 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
"Invalid read(%d,%p,%zu) return value %zd", fildes,
buf, nbyte, rval);
+ } else if (len_strict && (size_t)rval != nbyte) {
+ tst_brkm_(file, lineno, TBROK, cleanup_fn,
+ "Short read(%d,%p,%zu) returned only %zd",
+ fildes, buf, nbyte, rval);
}
return rval;
--
2.45.2
More information about the ltp
mailing list