mycpp

Coverage Report

Created: 2025-04-27 06:38

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