1 // RUN: %clangxx -std=c++11 -O0 -g %s -o %t && %run %t
7 static bool sahandler_done
;
8 static bool sasigaction_done
;
10 static void sahandler(int) { sahandler_done
= true; }
12 static void sasigaction(int, siginfo_t
*, void *) { sasigaction_done
= true; }
14 template <typename T
> void install(T
*handler
, struct sigaction
*prev
) {
15 bool siginfo
= handler
== (T
*)&sasigaction
;
16 struct sigaction act
= {};
18 act
.sa_flags
= SA_SIGINFO
;
19 act
.sa_sigaction
= (decltype(act
.sa_sigaction
))handler
;
21 act
.sa_handler
= (decltype(act
.sa_handler
))handler
;
23 int ret
= sigaction(SIGHUP
, &act
, prev
);
26 if (handler
== (T
*)&sahandler
) {
27 sahandler_done
= false;
29 assert(sahandler_done
);
32 if (handler
== (T
*)&sasigaction
) {
33 sasigaction_done
= false;
35 assert(sasigaction_done
);
39 template <typename T1
, typename T2
> void test(T1
*from
, T2
*to
) {
40 install(from
, nullptr);
41 struct sigaction prev
= {};
44 bool siginfo_from
= (from
== (T1
*)&sasigaction
);
46 assert(prev
.sa_flags
& SA_SIGINFO
);
47 assert(prev
.sa_sigaction
== (decltype(prev
.sa_sigaction
))from
);
49 assert((prev
.sa_flags
& SA_SIGINFO
) == 0);
50 assert(prev
.sa_handler
== (decltype(prev
.sa_handler
))from
);
54 template <typename T
> void testAll(T
*to
) {
56 test(&sasigaction
, to
);
63 testAll(&sasigaction
);