From c5d5e8873029d170fcab38a6fbd5d5a355574b9f Mon Sep 17 00:00:00 2001
From: Chen Qi <Qi.Chen@windriver.com>
Date: Wed, 4 Jun 2025 16:27:19 +0800
Subject: [PATCH] ts/kill/decode: use RTMIN from 'kill -L' instead of
 hardcoding 34

glibc uses 34 as the value of SIGRTMIN:
https://sourceware.org/git/?p=glibc.git;a=blob;f=signal/allocrtsig.c;h=8ed8e37dd6c41f94be6eef042ce9db1af1153228;hb=HEAD#l27 """
static int current_rtmin = __SIGRTMIN + RESERVED_SIGRT; """

musl uses 35 as the value of SIGRTMIN:
https://git.musl-libc.org/cgit/musl/tree/src/signal/sigrtmin.c

With the hardcoded 34, test case fails with the following difference:

-Ignored: HUP QUIT TRAP PIPE ALRM
+Ignored: HUP QUIT TRAP PIPE ALRM 34

Extract the value of RTMIN from 'kill -L' to avoid such hardcoding.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>

Upstream-Status: Backport [https://github.com/util-linux/util-linux/commit/c5d5e8873029d170fcab38a6fbd5d5a355574b9f]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 tests/ts/kill/decode | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/ts/kill/decode b/tests/ts/kill/decode
index 57149899e..524b4e5e2 100755
--- a/tests/ts/kill/decode
+++ b/tests/ts/kill/decode
@@ -53,14 +53,19 @@ ACK=
 	    # Sending one more USR1 is for making the signal pending state.
 	    "$TS_CMD_KILL" -USR1 "$PID"
 	    "$TS_CMD_KILL" -d "$PID" | {
-		if [[ $("$TS_CMD_KILL" --list=34) == RT0 ]]; then
+		SIGRTMIN=$("$TS_CMD_KILL" -L | grep -o '[0-9]\+ RTMIN' | cut -d " " -f 1)
+		if [[ $("$TS_CMD_KILL" --list=$SIGRTMIN) == RT0 ]]; then
 		    # See man signal(7).
 		    #   The  Linux  kernel  supports a range of 33 different real-time signals,
 		    #   numbered 32 to 64.  However, the glibc POSIX threads implementation in‐
 		    #   ternally uses two (for NPTL) or three (for LinuxThreads) real-time sig‐
 		    #   nals (see pthreads(7)), and adjusts the value of SIGRTMIN suitably  (to
 		    #   34 or 35).
-		    sed -e s/' 32 33'// -e s/' 34'//
+		    sed_cmd="sed"
+		    for ((i=32; i<=SIGRTMIN; i++)); do
+			sed_cmd+=" -e s/' $i'//"
+		    done
+		    eval $sed_cmd
 		else
 		    cat
 		fi
-- 
2.34.1

