Skip to contentSkip to conversation

sigrelse01: Check if signal 34 is available for musl compat

PATCH In review Florian Schmaus via ltp 2 participants 3 messages Aug 8, 2025 – Aug 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sigrelse01: Check if signal 34 is available for musl compat

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.

---

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(+)
testcases/kernel/syscalls/sigrelse/sigrelse01.c +25 -0
index d1ed9d53a4dc..d38479a7e590 100644
@@ -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)
Signature · 5 lines
2.49.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw
Quoted 6 lines · Florian Schmaus via ltp

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.

Quoted 6 lines

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.

This is wrong, the libc can use whatever (RT) signals it wants, and you're supposed to check for their availability using SIGRTMIN. This applies for both musl *and* glibc. The only difference is that glibc only needs 32 and 33, whereas musl also needs 34 (for now).

So, the correct fix would be to exclude all signals outside of [SIGRTMIN, SIGRTMAX]

Signature · 4 lines
Pedro

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 14 lines · Pedro Falcato
Quoted 6 lines · Florian Schmaus via ltp

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.

Quoted 6 lines

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.

Quoted 3 lines

[…]

So, the correct fix would be to exclude all signals outside of [SIGRTMIN, SIGRTMAX]

Thanks, this does the trick and reduces the size of the patch significantly. Will send v3 shortly.

- Florian

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp