cpp

Coverage Report

Created: 2025-05-19 02:30

/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
0
SignalSafe* InitSignalSafe() {
10
0
  gSignalSafe = Alloc<SignalSafe>();
11
0
  gHeap.RootGlobalVar(gSignalSafe);
12
13
0
  RegisterSignalInterest(SIGINT);  // for KeyboardInterrupt checks
14
15
0
  return gSignalSafe;
16
0
}
17
18
0
static void OurSignalHandler(int sig_num) {
19
0
  assert(gSignalSafe != nullptr);
20
0
  gSignalSafe->UpdateFromSignalHandler(sig_num);
21
0
}
22
23
0
void RegisterSignalInterest(int sig_num) {
24
0
  struct sigaction act = {};
25
0
  act.sa_handler = OurSignalHandler;
26
0
  if (sigaction(sig_num, &act, nullptr) != 0) {
27
0
    throw Alloc<OSError>(errno);
28
0
  }
29
0
}
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
0
void sigaction(int sig_num, void (*handler)(int)) {
35
  // SIGINT and SIGWINCH must be registered through SignalSafe
36
0
  DCHECK(sig_num != SIGINT);
37
0
  DCHECK(sig_num != SIGWINCH);
38
39
0
  struct sigaction act = {};
40
0
  act.sa_handler = handler;
41
0
  if (sigaction(sig_num, &act, nullptr) != 0) {
42
0
    throw Alloc<OSError>(errno);
43
0
  }
44
0
}
45
46
}  // namespace iolib