[LTP] [PATCH 05/19] Unify error handling in lib/safe_macros.c

Cyril Hrubis chrubis@suse.cz
Wed Nov 11 13:58:31 CET 2020


Hi!
> @@ -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);
>  	}

Shouldn't this be else if as well? Since otherwise we may generate two
warning messages if in cleanup() read() returns -1.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list