[LTP] [PATCH v2] sigrelse01: Check if signal 34 is available for musl compat

Florian Schmaus florian.schmaus@codasip.com
Fri Aug 8 18:34:57 CEST 2025


Do not select signal 34 when the test is run using musl. Signal 34 is
used internally by musl as SIGSYNCCALL. Consequently, musl's signal()
will return with an error status and errno set to EINVAL when trying
to setup a signal handler for signal 34, causing the sigrelse01 test
to fail.

Since musl provides no preprocessor macro, we check for the
availability of signal 34 by attempting to setup a signal handler. If
signal() returns SIG_ERR with errno set to EINVAL then we assume the
signal is unavailable. Knowing signal 34 is available with glibc, we
perform this check only if __GLIBC__ is not defined.

Signed-off-by: Florian Schmaus <florian.schmaus@codasip.com>
---

Changes since v1:
    - do not declare _GNU_SOURCE, as a result signal() returns void*
    - do not use stdbool

 .../kernel/syscalls/sigrelse/sigrelse01.c     | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/testcases/kernel/syscalls/sigrelse/sigrelse01.c b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
index d1ed9d53a4dc..d38479a7e590 100644
--- a/testcases/kernel/syscalls/sigrelse/sigrelse01.c
+++ b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
@@ -177,6 +177,8 @@ static int sig_caught;		/* flag TRUE if signal caught */
 /* array of counters for signals caught by handler() */
 static int sig_array[NUMSIGS];
 
+static int sig34_available = TRUE; /* Signal 34 is unavailable on e.g., musl */
+
 /***********************************************************************
  *   M A I N
  ***********************************************************************/
@@ -736,6 +738,8 @@ int choose_sig(int sig)
 	case SIGSWAP:
 #endif
 		return 0;
+	case 34:
+		return sig34_available;
 
 	}
 
@@ -773,6 +777,27 @@ void setup(void)
 	if (fcntl(pipe_fd2[0], F_SETFL, O_NONBLOCK) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "fcntl(Fds[0], F_SETFL, O_NONBLOCK) failed");
+
+#ifndef __GLIBC__
+	/*
+	 * Check if signal 34 is available. Some libc implementations do
+	 * not support signal 34. For example, musl uses signal 34 as
+	 * internal signal (SIGSYNCCALL).
+	 */
+	void *previous = signal(34, handler);
+	if (previous == SIG_ERR) {
+		if (errno == EINVAL)
+			sig34_available = FALSE;
+		else
+			tst_brkm(TBROK | TERRNO, cleanup,
+				 "signal(34, handler) failed");
+	} else {
+		/* Restore the original handler */
+		if (signal(34, previous) == SIG_ERR)
+			tst_brkm(TBROK | TERRNO, cleanup,
+					 "signal(34, handler) failed");
+	}
+#endif
 }
 
 void cleanup(void)
-- 
2.49.1



More information about the ltp mailing list