From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] safe_macros: Fix confusing safe_read() failure output
Date: Thu, 16 Jan 2025 12:19:25 +0100 [thread overview]
Message-ID: <20250116111925.GB679477@pevik> (raw)
In-Reply-To: <Z4jqWbkdTsfVmfZL@yuki.lan>
Hi Cyril,
> Hi!
> > > 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
> > nit: s/ernno/errno/
> > > message on a short read() while developing tests.
> > Good catch!
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Pushed, thanks.
> > FYI safe_write() also has TERRNO in len_strict.
> > Kind regards,
> > Petr
> > +++ lib/safe_macros.c
> > @@ -554,7 +554,7 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
> > if (len_strict == SAFE_WRITE_ALL) {
> > if ((size_t)rval != nbyte)
> > - tst_brkm_(file, lineno, TBROK | TERRNO,
> > + tst_brkm_(file, lineno, TBROK,
> > cleanup_fn, "short write(%d,%p,%zu) "
> > "return value %zd",
> > fildes, buf, nbyte, rval);
> I guess that we are missing check for invalid return value from write()
> as well and return in the rval == -1 branch, we probably need to add:
> diff --git a/lib/safe_macros.c b/lib/safe_macros.c
> index b224a5861..3d3e7c693 100644
> --- a/lib/safe_macros.c
> +++ b/lib/safe_macros.c
> @@ -551,6 +551,14 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
> tst_brkm_(file, lineno, TBROK | TERRNO,
> cleanup_fn, "write(%d,%p,%zu) failed",
> fildes, buf, nbyte);
> + return rval;
> + }
> +
> + if (rval < 0) {
> + tst_brkm_(file, lineno, TBROK, cleanup_fn,
> + "invalid write() return value %zi",
> + rval);
> + return rval;
> }
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Please merge it directly (ideally with link to this discussion on lore).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-01-16 11:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 15:03 [LTP] [PATCH] safe_macros: Fix confusing safe_read() failure output Cyril Hrubis
2025-01-09 16:18 ` Petr Vorel
2025-01-16 11:15 ` Cyril Hrubis
2025-01-16 11:19 ` Petr Vorel [this message]
2025-01-16 12:01 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250116111925.GB679477@pevik \
--to=pvorel@suse.cz \
--cc=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox