]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/signal/tst-signalfd.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / signal / tst-signalfd.c
1 /* vi: set sw=4 ts=4 sts=4: */
2 /*
3  * signalfd test for uClibc
4  * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <error.h>
15 #include <signal.h>
16 #include <sys/signalfd.h>
17 #include <sys/fcntl.h>
18
19 static int
20 do_test(void)
21 {
22         int fd, ret, result = 0;
23         struct signalfd_siginfo ssi;
24         sigset_t mask;
25
26         sigemptyset(&mask);
27         sigaddset(&mask, SIGUSR1);
28         sigprocmask(SIG_BLOCK, &mask, NULL);
29
30         fd = signalfd(-1, &mask, SFD_NONBLOCK);
31         if (fd < 0) {
32                 printf("signalfd() failed: %s\n", strerror(errno));
33                 result = 1;
34         }
35
36         /* this should return immediately with EAGAIN due to SFD_NONBLOCK */
37         memset(&ssi, 0, sizeof(ssi));
38         ret = read(fd, &ssi, sizeof(ssi));
39         if (ret != -1 || errno != EAGAIN) {
40                 error(0, 0, "first read() returned %d", ret);
41                 result = 1;
42         }
43
44         kill(getpid(), SIGUSR1);
45
46         /* this should return a struct ssi indicating receipt of SIGUSR1 */
47         ret = read(fd, &ssi, sizeof(ssi));
48         if (ret != sizeof(ssi)) {
49                 error(0, 0, "second read() returned %d", ret);
50                 result = 1;
51         }
52
53         if (ssi.ssi_signo != SIGUSR1) {
54                 error(0, 0, "ssi contains bogus signo");
55                 result = 1;
56         }
57
58         return result;
59 }
60
61 #define TIMEOUT 5
62 #define TEST_FUNCTION do_test ()
63 #include "../test-skeleton.c"