ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 05/19] Unify error handling in lib/safe_macros.c
Date: Tue, 27 Oct 2020 18:10:13 +0800	[thread overview]
Message-ID: <5F97F205.8020602@cn.fujitsu.com> (raw)
In-Reply-To: <20201026164756.30556-6-mdoucha@suse.cz>

Hi Martin
> - Properly format caller file:line location
> - Pedantically check invalid syscall return values
>
> Signed-off-by: Martin Doucha<mdoucha@suse.cz>
> ---
>   lib/safe_macros.c | 602 +++++++++++++++++++++++++++++-----------------
>   1 file changed, 384 insertions(+), 218 deletions(-)
>
> diff --git a/lib/safe_macros.c b/lib/safe_macros.c
> index 4f48d7529..f5e80fc48 100644
> --- a/lib/safe_macros.c
> +++ b/lib/safe_macros.c

>
>
>   	return rval;
> @@ -255,10 +288,16 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),
>   	ssize_t rval;
>
>   	rval = read(fildes, buf, nbyte);
> +
>   	if (rval == -1 || (len_strict&&  (size_t)rval != nbyte)) {
> -		tst_brkm(TBROK | TERRNO, cleanup_fn,
> -			 "%s:%d: read(%d,%p,%zu) failed, returned %zd",
> -			 file, lineno, fildes, buf, nbyte, rval);
> +		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
> +			"read(%d,%p,%zu) failed, returned %zd", fildes, buf,
> +			nbyte, rval);
> +	}
> +	if (rval<  0) {
> +		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
> +			"Invalid read(%d,%p,%zu) return value %zd", fildes,
> +			buf, nbyte, rval);
>   	}
Here has problem.. Maybe we can  use simple
if (rval < 0 || (len_strict&&  (size_t)rval != nbyte)) to replace.
>
>   	return rval;

>   	return rval;
> @@ -452,10 +530,14 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),
>   	ssize_t rval;
>
>   	rval = write(fildes, buf, nbyte);
> +
>   	if (rval == -1 || (len_strict&&  (size_t)rval != nbyte)) {
> -		tst_brkm(TBROK | TERRNO, cleanup_fn,
> -			 "%s:%d: write(%d,%p,%zu) failed",
> -		         file, lineno, fildes, buf, rval);
> +		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
> +			"write(%d,%p,%zu) failed", fildes, buf, nbyte);
> +	} else if (rval<  0) {
> +		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
> +			"Invalid write(%d,%p,%zu) return value %zd", fildes,
> +			buf, nbyte, rval);
>   	}
I prefer to use "if (rval < 0 || (len_strict&&  (size_t)rval != nbyte)"
>

>   	}
>
> @@ -530,20 +612,19 @@ long safe_sysconf(const char *file, const int lineno,
>   		  void (cleanup_fn) (void), int name)
>   {
>   	long rval;
> -	errno = 0;
>
> +	errno = 0;
It looks no change.
>   	rval = sysconf(name);
>
>   	if (rval == -1) {
>   		if (errno) {
> -			tst_brkm(TBROK | TERRNO, cleanup_fn,
> -				 "%s:%d: sysconf(%d) failed",
> -				 file, lineno, name);
> +			tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
> +				"sysconf(%d) failed", name);
>   		} else {
> -			tst_resm(TINFO, "%s:%d: sysconf(%d): "
> -				 "queried option is not available"
> -				 " or there is no definite limit",
> -				 file, lineno, name);
> +			tst_resm_(file, lineno, TINFO, "sysconf(%d): "
> +				"queried option is not available"
> +				" or there is no definite limit",
> +				name);
>   		}





  reply	other threads:[~2020-10-27 10:10 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 16:47 [LTP] [PATCH 00/19] Unify error handling in LTP library Martin Doucha
2020-10-26 16:47 ` [LTP] [PATCH 01/19] Unify error handling in lib/tst_safe_macros.c Martin Doucha
2020-10-27  8:22   ` Yang Xu
2020-10-29 15:35   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 02/19] Unify error handling in lib/tst_safe_sysv_ipc.c Martin Doucha
2020-10-27  9:10   ` Yang Xu
2020-10-26 16:47 ` [LTP] [PATCH 03/19] Unify error handling in lib/tst_safe_timerfd.c Martin Doucha
2020-10-27  9:21   ` Yang Xu
2020-11-06 17:35     ` Petr Vorel
2020-11-07  0:22       ` Yang Xu
2020-11-07 16:42         ` Petr Vorel
2020-10-26 16:47 ` [LTP] [PATCH 04/19] Unify error handling in lib/safe_file_ops.c Martin Doucha
2020-10-29 15:59   ` Cyril Hrubis
2020-10-29 16:02     ` Cyril Hrubis
2020-10-29 16:05       ` Martin Doucha
2020-10-29 16:17         ` Cyril Hrubis
2020-10-29 16:23           ` Martin Doucha
2020-10-30 10:31             ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 05/19] Unify error handling in lib/safe_macros.c Martin Doucha
2020-10-27 10:10   ` Yang Xu [this message]
2020-10-27 10:51     ` Martin Doucha
2020-11-11 12:58   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 06/19] Unify error handling in lib/safe_net.c Martin Doucha
2020-11-11 12:53   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 07/19] Unify error handling in lib/safe_stdio.c Martin Doucha
2020-11-10 16:11   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 08/19] Unify error handling in lib/tst_mkfs.c Martin Doucha
2020-11-10 15:43   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 09/19] Unify error handling in lib/tst_checkpoint.c Martin Doucha
2020-11-10 15:17   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 10/19] Unify error handling in lib/tst_net.c Martin Doucha
2020-11-10 13:20   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 11/19] Unify error handling in lib/tst_fs_setup.c Martin Doucha
2020-10-27 13:12   ` Yang Xu
2020-10-26 16:47 ` [LTP] [PATCH 12/19] Unify error handling in include/tst_safe_clocks.h Martin Doucha
2020-11-10 13:13   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 13/19] Move executable code out of tst_safe_macros.h Martin Doucha
2020-10-26 16:47 ` [LTP] [PATCH 14/19] Unify error handling in moved functions Martin Doucha
2020-11-10 12:18   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 15/19] Unify error handling in include/tst_safe_macros.h Martin Doucha
2020-11-10 11:37   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 16/19] Unify error handling in include/tst_safe_posix_ipc.h Martin Doucha
2020-11-06 15:43   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 17/19] Unify error handling in include/tst_safe_prw.h Martin Doucha
2020-11-06 15:39   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 18/19] Unify error handling in lib/tst_resource.c Martin Doucha
2020-11-06 13:05   ` Cyril Hrubis
2020-10-26 16:47 ` [LTP] [PATCH 19/19] Unify error handling in include/lapi/safe_rt_signal.h Martin Doucha
2020-11-06 12:57   ` Cyril Hrubis
2020-10-27 13:32 ` [LTP] [PATCH 00/19] Unify error handling in LTP library Yang Xu

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=5F97F205.8020602@cn.fujitsu.com \
    --to=xuyang2018.jy@cn.fujitsu.com \
    --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;
as well as URLs for NNTP newsgroup(s).