2003-11-13 09:48:31 +03:00
|
|
|
/* $NetBSD: sigalrm.c,v 1.3 2003/11/13 06:48:31 simonb Exp $ */
|
|
|
|
|
2003-09-14 10:54:28 +04:00
|
|
|
#include <assert.h>
|
2003-09-07 02:27:22 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2003-09-14 10:54:28 +04:00
|
|
|
#include <sys/time.h>
|
2003-09-07 02:27:22 +04:00
|
|
|
#include <sys/ucontext.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
sigalrm(int signo, siginfo_t *info, void *ptr)
|
|
|
|
{
|
2003-09-14 10:54:28 +04:00
|
|
|
#ifdef DEBUG
|
2003-09-07 02:27:22 +04:00
|
|
|
printf("%d %p %p\n", signo, info, ptr);
|
|
|
|
if (info != NULL) {
|
|
|
|
printf("si_signo=%d\n", info->si_signo);
|
|
|
|
printf("si_errno=%d\n", info->si_errno);
|
|
|
|
printf("si_code=%d\n", info->si_code);
|
2003-09-14 10:54:28 +04:00
|
|
|
printf("si_sigval.sival_int=%d\n", info->si_sigval.sival_int);
|
2003-09-07 02:27:22 +04:00
|
|
|
}
|
|
|
|
if (ptr != NULL) {
|
|
|
|
ucontext_t *ctx = ptr;
|
|
|
|
int i;
|
|
|
|
mcontext_t *mc = &ctx->uc_mcontext;
|
|
|
|
printf("uc_flags 0x%x\n", ctx->uc_flags);
|
|
|
|
printf("uc_link %p\n", ctx->uc_link);
|
|
|
|
for (i = 0; i < sizeof(ctx->uc_sigmask.__bits) /
|
|
|
|
sizeof(ctx->uc_sigmask.__bits[0]); i++)
|
|
|
|
printf("uc_sigmask[%d] 0x%x\n", i,
|
|
|
|
ctx->uc_sigmask.__bits[i]);
|
|
|
|
printf("uc_stack %p %lu 0x%x\n", ctx->uc_stack.ss_sp,
|
|
|
|
(unsigned long)ctx->uc_stack.ss_size,
|
|
|
|
ctx->uc_stack.ss_flags);
|
|
|
|
for (i = 0; i < sizeof(mc->__gregs)/sizeof(mc->__gregs[0]); i++)
|
|
|
|
printf("uc_mcontext.greg[%d] 0x%x\n", i,
|
|
|
|
mc->__gregs[i]);
|
|
|
|
}
|
2003-09-14 10:54:28 +04:00
|
|
|
#endif
|
|
|
|
assert(info->si_signo == SIGALRM);
|
|
|
|
assert(info->si_code == SI_TIMER);
|
|
|
|
assert(info->si_sigval.sival_int == ITIMER_REAL);
|
|
|
|
exit(0);
|
2003-09-07 02:27:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
sa.sa_sigaction = sigalrm;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sigaction(SIGALRM, &sa, NULL);
|
|
|
|
for (;;) {
|
|
|
|
alarm(1);
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|