/home/uke/oil/mycpp/gc_iolib.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "mycpp/gc_iolib.h" |
2 | | |
3 | | #include <errno.h> |
4 | | |
5 | | namespace iolib { |
6 | | |
7 | | SignalSafe* gSignalSafe = nullptr; |
8 | | |
9 | 2 | SignalSafe* InitSignalSafe() { |
10 | 2 | gSignalSafe = Alloc<SignalSafe>(); |
11 | 2 | gHeap.RootGlobalVar(gSignalSafe); |
12 | | |
13 | 2 | RegisterSignalInterest(SIGINT); // for KeyboardInterrupt checks |
14 | | |
15 | 2 | return gSignalSafe; |
16 | 2 | } |
17 | | |
18 | 8 | static void OurSignalHandler(int sig_num) { |
19 | 8 | assert(gSignalSafe != nullptr); |
20 | 0 | gSignalSafe->UpdateFromSignalHandler(sig_num); |
21 | 8 | } |
22 | | |
23 | 8 | void RegisterSignalInterest(int sig_num) { |
24 | 8 | struct sigaction act = {}; |
25 | 8 | act.sa_handler = OurSignalHandler; |
26 | 8 | if (sigaction(sig_num, &act, nullptr) != 0) { |
27 | 0 | throw Alloc<OSError>(errno); |
28 | 0 | } |
29 | 8 | } |
30 | | |
31 | | // Note that the Python implementation of pyos.sigaction() calls |
32 | | // signal.signal(), which calls PyOS_setsig(), which calls sigaction() #ifdef |
33 | | // HAVE_SIGACTION. |
34 | 4 | void sigaction(int sig_num, void (*handler)(int)) { |
35 | | // SIGINT and SIGWINCH must be registered through SignalSafe |
36 | 4 | DCHECK(sig_num != SIGINT); |
37 | 4 | DCHECK(sig_num != SIGWINCH); |
38 | | |
39 | 0 | struct sigaction act = {}; |
40 | 4 | act.sa_handler = handler; |
41 | 4 | if (sigaction(sig_num, &act, nullptr) != 0) { |
42 | 0 | throw Alloc<OSError>(errno); |
43 | 0 | } |
44 | 4 | } |
45 | | |
46 | | } // namespace iolib |