[LTP] added SAFE_SOCKETPAIR()

Petr Vorel pvorel@suse.cz
Tue Dec 11 21:08:03 CET 2018


Hi Ramon,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> +++ b/lib/safe_net.c
> @@ -132,6 +132,34 @@ int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
>  	return rval;
>  }
> +int safe_socketpair(const char *file, const int lineno, int domain, int type,
> +		    int protocol, int sv[])
> +{
> +	int rval, ttype;
> +
> +	rval = socketpair(domain, type, protocol, sv);
> +
> +	if (rval < 0) {
> +		switch (errno) {
> +		case EPROTONOSUPPORT:
> +		case ESOCKTNOSUPPORT:
> +		case EOPNOTSUPP:
> +		case EPFNOSUPPORT:
> +		case EAFNOSUPPORT:
> +			ttype = TCONF;
> +			break;
> +		default:
> +			ttype = TBROK;
> +		}
It looks like you copy paste errno's from safe_socket(). While it does not harm
to have more errno's, I guess these to never come: ESOCKTNOSUPPORT, EPFNOSUPPORT.
They're listed in safe_socket() as man socket(2) says "Other errors may be
generated by the underlying protocol modules.", it was needed to ad them.

Otherwise LGTM.

> +
> +		tst_brkm(ttype | TERRNO, NULL,
> +			 "%s:%d: socketpair(%d, %d, %d, %p) failed",
> +			 file, lineno, domain, type, protocol, sv);
...


Kind regards,
Petr


More information about the ltp mailing list