diff options
author | H. Peter Anvin <hpa@zytor.com> | 2005-03-10 01:24:48 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2005-03-10 01:24:48 +0000 |
commit | 9991f3014e2cb90439682ac009e02d445f5f0e59 (patch) | |
tree | d531893f8829144ffff0ddd58942f9a69dfebfd4 | |
parent | 9e997973be0b22dcf5e8c28a02d7992c228c9c8d (diff) | |
download | klibc-9991f3014e2cb90439682ac009e02d445f5f0e59.tar.gz |
Fix sig_atomic_t, add signal handler testklibc-1.0.4
-rw-r--r-- | include/signal.h | 2 | ||||
-rw-r--r-- | klibc/tests/sigint.c | 49 |
2 files changed, 50 insertions, 1 deletions
diff --git a/include/signal.h b/include/signal.h index e78318f5f7424..ab3c98d6e4cfa 100644 --- a/include/signal.h +++ b/include/signal.h @@ -16,7 +16,7 @@ /* glibc seems to use sig_atomic_t as "int" pretty much on all architectures. Do the same, but allow the architecture to override. */ -#ifdef _KLIBC_HAS_ARCH_SIG_ATOMIC_T +#ifndef _KLIBC_HAS_ARCH_SIG_ATOMIC_T typedef int sig_atomic_t; #endif diff --git a/klibc/tests/sigint.c b/klibc/tests/sigint.c new file mode 100644 index 0000000000000..9899383d751d3 --- /dev/null +++ b/klibc/tests/sigint.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +static sig_atomic_t counter = 0; + +static void sig_handler(int signum) +{ + static char msg[] = "Signal handler\n"; + + (void)signum; + + write(1, msg, sizeof msg - 1); + counter++; +} + +int main(int argc, char *argv[]) +{ + struct sigaction act; + pid_t f; + + memset(&act, 0x00, sizeof(struct sigaction)); + act.sa_handler = sig_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_RESTART; + sigaction(SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); + + (void)argc; + + f = fork(); + + if ( f < 0 ) { + perror(argv[0]); + exit(255); + } else if ( f > 0 ) { + sleep(5); + if ( !counter ) { + fprintf(stderr, "No signal received!\n"); + exit(1); + } + exit(0); + } else { + sleep(1); + kill(getppid(), SIGINT); + exit(0); + } +} |