Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / sigalarm / sigalarm.c
blob5aaca8ad09281fe7fc78de4f5243e8d68cb97cb8
1 /* $NetBSD: sigalarm.c,v 1.1 2003/09/12 21:15:06 christos Exp $ */
3 /*
4 * Regression test for sigsuspend in libpthread when pthread lib is
5 * initialized.
6 */
8 #include <assert.h>
9 #include <err.h>
10 #include <stdio.h>
11 #include <signal.h>
12 #include <unistd.h>
13 #include <pthread.h>
16 int alarm_set;
18 #ifdef SA_SIGINFO
19 static void alarm_handler(int, siginfo_t *, void *);
20 static void
21 alarm_handler(int signo, siginfo_t *si, void *ctx)
23 if (si->si_signo != signo)
24 errx(1, "Received unexpected signal %d", signo);
25 alarm_set = 1;
27 #else
28 static void alarm_handler(int);
29 static void
30 alarm_handler(int signo)
32 if (SIGALRM != signo)
33 errx(1, "Received unexpected signal %d", signo);
34 alarm_set = 1;
36 #endif
38 static void *
39 setup(void *dummy)
41 struct sigaction sa;
42 sigset_t ss;
43 #ifdef SA_SIGINFO
44 sa.sa_flags = SA_SIGINFO;
45 sa.sa_sigaction = alarm_handler;
46 #else
47 sa.sa_flags = 0;
48 sa.sa_handler = alarm_handler;
49 #endif
50 sigfillset(&ss);
51 sigprocmask(SIG_SETMASK, &ss, NULL);
52 sigemptyset(&sa.sa_mask);
53 sigaction(SIGALRM, &sa, NULL);
54 alarm(1);
55 return NULL;
58 int
59 main(int argc, char **argv)
61 sigset_t set;
62 pthread_t self = pthread_self();
64 if (pthread_create(&self, NULL, setup, NULL) != 0)
65 err(1, "Cannot create thread");
67 sigemptyset(&set);
68 sigsuspend(&set);
69 alarm(0);
71 if (!alarm_set)
72 errx(1, "alarm_set not set");
73 return 0;