tests: More portable installation of SIGINT handler

Our tests install SIGINT handlers using sigaction(), but that isn't
available on Windows / mingw, blocking use of the tests there.  Use the
more portable signal() instead - it's good enough for our needs.  Avoid
strsignal() for the same reason.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2026-05-26 19:57:14 +10:00
parent 84d13508d5
commit d320877b07
2 changed files with 8 additions and 10 deletions

View file

@ -42,24 +42,21 @@ static inline void VALGRIND_MAKE_MEM_DEFINED(void *p, size_t len)
int verbose_test = 1;
char *test_name;
static void sigint_handler(int signum, siginfo_t *si, void *uc)
static void sigint_handler(int signum)
{
fprintf(stderr, "%s: %s (pid=%d)\n", test_name,
strsignal(signum), getpid());
fprintf(stderr, "%s: signal %d (pid=%d)\n", test_name,
signum, getpid());
exit(RC_BUG);
}
void test_init(int argc, char *argv[])
{
int err;
struct sigaction sa_int = {
.sa_sigaction = sigint_handler,
};
test_name = argv[0];
err = sigaction(SIGINT, &sa_int, NULL);
if (err)
/* Use signal(), not sigaction() because it also works on the Windows /
* mingw environments we support.
*/
if (signal(SIGINT, sigint_handler) == SIG_ERR)
FAIL("Can't install SIGINT handler");
if (getenv("QUIET_TEST"))