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

@ -86,6 +86,7 @@ See the "AI Coding Assistants" section in CONTRIBUTING.md. Key rules:
- **Do not** add `Signed-off-by` tags — only humans can certify the DCO - **Do not** add `Signed-off-by` tags — only humans can certify the DCO
- Use `Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]` for attribution in commit messages - Use `Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]` for attribution in commit messages
- The human submitter is responsible for reviewing all AI-generated code and ensuring license compliance - The human submitter is responsible for reviewing all AI-generated code and ensuring license compliance
- Do not add `Co-authored-by` tags.
## Tagging a New Release ## Tagging a New Release

View file

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