Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mptcp: info: hide 'grep: write error' warnings

mptcp_lib_get_info_value() will only print the first entry that match
the filter because of the ';q' at the end. As a consequence, the 'sed'
command could finish before the previous 'grep' one and print a 'write
error' warning because it is trying to write data to the closed pipe.

Such warnings are not interesting, they can be hidden by muting stderr
here for grep.

While at it, clearly indicate that mptcp_lib_get_info_value() will only
print the first matched entry to avoid confusions later on.

Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250502-net-next-mptcp-sft-inc-cover-v1-1-68eec95898fb@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Matthieu Baerts (NGI0) and committed by
Jakub Kicinski
6d0eb15c ac8f09b9

+5 -2
+5 -2
tools/testing/selftests/net/mptcp/mptcp_lib.sh
··· 331 331 332 332 # get the value of keyword $1 in the line marked by keyword $2 333 333 mptcp_lib_get_info_value() { 334 - grep "${2}" | sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q' 334 + grep "${2}" 2>/dev/null | 335 + sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q' 336 + # the ';q' at the end limits to the first matched entry. 335 337 } 336 338 337 339 # $1: info name ; $2: evts_ns ; [$3: event type; [$4: addr]] 338 340 mptcp_lib_evts_get_info() { 339 - grep "${4:-}" "${2}" | mptcp_lib_get_info_value "${1}" "^type:${3:-1}," 341 + grep "${4:-}" "${2}" 2>/dev/null | 342 + mptcp_lib_get_info_value "${1}" "^type:${3:-1}," 340 343 } 341 344 342 345 # $1: PID