[PATCH] net: enhance decoding of getsockopt(SO_ERROR)

Dmitry V. Levin ldv at altlinux.org
Sun Dec 16 00:17:09 UTC 2018


On Sun, Dec 16, 2018 at 07:05:28AM +0900, Masatake YAMATO wrote:
> * net.c (print_get_error): New function decoding error
> number returned as option value for SO_ERROR option.
> (print_getsockopt) <case SO_ERROR>: Call print_get_error.
> 
> * tests/so_error.c: New test.
> * tests/gen_tests.in (so_error): Likewise.
> * tests/pure_executables.list (so_error): Likewise.
> 
> Signed-off-by: Masatake YAMATO <yamato at redhat.com>
> ---
>  net.c                       |  23 +++++++
>  tests/gen_tests.in          |   1 +
>  tests/pure_executables.list |   1 +
>  tests/so_error.c            | 121 ++++++++++++++++++++++++++++++++++++
>  4 files changed, 146 insertions(+)
>  create mode 100644 tests/so_error.c
> 
> diff --git a/net.c b/net.c
> index f65b6619..4b2cba04 100644
> --- a/net.c
> +++ b/net.c
> @@ -671,6 +671,26 @@ print_get_ucred(struct tcb *const tcp, const kernel_ulong_t addr,
>  	tprints("}");
>  }
>  
> +static void
> +print_get_error(struct tcb *const tcp, const kernel_ulong_t addr,
> +		unsigned int len)
> +{
> +	unsigned int err;
> +	const char *ename;
> +
> +	if (len > sizeof(err))
> +		err = sizeof(err);
> +
> +	if (umoven_or_printaddr(tcp, addr, len, &err))
> +		return;
> +
> +	ename = err_name (err);
> +	if (ename)
> +		tprintf("[%s]", ename);
> +	else
> +		tprintf("[%u]", err);

Thanks.  I think it should use something like

	tprints("[");
	print_xlat_ex(err, err_name(err), XLAT_STYLE_FMT_U);
	tprints("]");

to provide xlat styles support.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20181216/46aa804f/attachment.bin>


More information about the Strace-devel mailing list