Re: [PATCH mptcp-next] selftests: mptcp: print stats before socket closure

Paolo Abeni <[email protected]>
Newsgroups dev.linux.lists.mptcp
Message-ID <[email protected]>
On 8/14/26 4:07 PM, Matthieu Baerts (NGI0) wrote:
> In case of poll timeout, it might be too late to print the stats after
> the socket closure.
> 
> Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
> mptcp_connect to print the stats before exiting. This should help
> debugging poll timeout issues.
> 
> Note: for this "workaround", system() is used for debugging purposes
> only. The returned result can then be safely ignored.
> 
> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
> ---
>  tools/testing/selftests/net/mptcp/mptcp_connect.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index ea4cb6c1bd5e..842c0eb99aa9 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const char *service,
>  	}
>  }
>  
> +static void print_err_stats(void)
> +{
> +	char cmd[128];
> +
> +	snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s' >&2",
> +		 listen_mode ? 's' : 'd', cfg_port);
> +
> +	fprintf(stderr, "socket stats before socket closure:\n");
> +	(void)!system(cmd);
> +	(void)!system("NSTAT_HISTORY='/tmp/$(ip netns id).nstat' nstat -s | "
> +		      "grep Tcp >&2");

Overall LGTM. I tried something similar in the past, but the correct
redirection always fouled me. A couple of questions:
- Is the '!' operator needed?
- Can we avoid the pipe? with something alike the following:
	(void)system("NSTAT_HISTORY='/tmp/$(ip netns id).nstat' nstat -s *Tcp*
>&2");

/P
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.