ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH] sigrelse01: Check if signal 34 is available for musl compat
@ 2025-07-31  6:57 Florian Schmaus via ltp
  2025-08-08 14:04 ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Schmaus via ltp @ 2025-07-31  6:57 UTC (permalink / raw)
  To: 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.

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>
---
 .../kernel/syscalls/sigrelse/sigrelse01.c     | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/testcases/kernel/syscalls/sigrelse/sigrelse01.c b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
index d1ed9d53a4dc..130fea7f9bc3 100644
--- a/testcases/kernel/syscalls/sigrelse/sigrelse01.c
+++ b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
@@ -98,11 +98,14 @@
  *
 ***************************************************************************/
 
+#define _GNU_SOURCE
+
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -177,6 +180,8 @@ static int sig_caught;		/* flag TRUE if signal caught */
 /* array of counters for signals caught by handler() */
 static int sig_array[NUMSIGS];
 
+static bool sig34_available = true; /* Signal 34 is unavailable on e.g., musl */
+
 /***********************************************************************
  *   M A I N
  ***********************************************************************/
@@ -736,6 +741,8 @@ int choose_sig(int sig)
 	case SIGSWAP:
 #endif
 		return 0;
+	case 34:
+		return sig34_available;
 
 	}
 
@@ -773,6 +780,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).
+	 */
+	sighandler_t 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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-08 16:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-31  6:57 [LTP] [PATCH] sigrelse01: Check if signal 34 is available for musl compat Florian Schmaus via ltp
2025-08-08 14:04 ` Petr Vorel
2025-08-08 16:06   ` Florian Schmaus via ltp
2025-08-08 16:45     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).