1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include <stdio.h>
#include <assert.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
pid_t parent;
pid_t child;
int fds[2];
void parent_fn() {
int res;
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGUSR2);
sigprocmask(SIG_BLOCK, &set, NULL);
res = write(fds[1], "!", 1);
assert(res == 1);
siginfo_t info;
res = sigwaitinfo(&set, &info);
assert(res == SIGUSR2);
assert(info.si_signo == SIGUSR2);
res = write(fds[1], "!", 1);
assert(res == 1);
// XXX: This may not be long enough to get scheduled
struct timespec tout = {1, 0};
res = sigtimedwait(&set, &info, &tout);
assert(res == SIGUSR2);
assert(info.si_signo == SIGUSR2);
res = write(fds[1], "!", 1);
assert(res == 1);
int sig;
res = sigwait(&set, &sig);
assert(res == 0);
assert(sig == SIGUSR2);
res = write(fds[1], "!", 1);
assert(res == 1);
res = sigtimedwait(&set, &info, &tout);
assert(res < 0);
assert(errno == EAGAIN);
int wsts;
res = waitpid(child, &wsts, 0);
assert(res >= 0);
}
void child_fn() {
int res;
char c;
res = read(fds[0], &c, 1);
assert(res == 1);
kill(parent, SIGUSR2);
res = read(fds[0], &c, 1);
assert(res == 1);
kill(parent, SIGUSR2);
res = read(fds[0], &c, 1);
assert(res == 1);
kill(parent, SIGUSR2);
res = read(fds[0], &c, 1);
assert(res == 1);
}
int main() {
int res;
parent = getpid();
assert(parent > 0);
res = pipe(fds);
assert(res == 0);
child = fork();
assert(child >= 0);
if (child)
parent_fn();
else
child_fn();
}
|