YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/signal_util.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
13
#include "yb/util/signal_util.h"
14
15
#include <signal.h>
16
#include "yb/util/errno.h"
17
18
namespace yb {
19
20
1.99k
Result<sigset_t> ThreadSignalMaskBlock(const std::vector<int>& signals_to_block) {
21
  // Note that in case of an error sigaddset sets errno and returns -1
22
  // while pthread_sigmask returns errno directly.
23
24
1.99k
  sigset_t mask;
25
1.99k
  sigemptyset(&mask);
26
9.97k
  for (int sig : signals_to_block) {
27
9.97k
    int err = sigaddset(&mask, sig);
28
9.97k
    if (err != 0) {
29
0
      return STATUS(InternalError, "sigaddset failed", Errno(errno));
30
0
    }
31
9.97k
  }
32
33
1.99k
  sigset_t old_mask;
34
1.99k
  int err = pthread_sigmask(SIG_BLOCK, &mask, &old_mask);
35
1.99k
  return (err == 0
36
1.99k
      ? Result<sigset_t>(old_mask)
37
1.99k
      : 
STATUS0
(InternalError, "SIG_BLOCK failed", Errno(err)));
38
1.99k
}
39
40
1.99k
Status ThreadSignalMaskRestore(sigset_t old_mask) {
41
1.99k
  int err = pthread_sigmask(SIG_SETMASK, &old_mask, NULL /* oldset */);
42
1.99k
  return (err == 0
43
1.99k
      ? Status::OK()
44
1.99k
      : 
STATUS0
(InternalError, "SIG_SETMASK failed", Errno(err)));
45
1.99k
}
46
47
const std::vector<int> kYsqlHandledSignals{
48
    // Following handlers are installed in StartBackgroundWorker:
49
    SIGINT, // StatementCancelHandler
50
    SIGUSR1, // procsignal_sigusr1_handler
51
    SIGFPE, // FloatExceptionHandler
52
    SIGTERM, // bgworker_die
53
    SIGQUIT // bgworker_quickdie
54
};
55
56
1.99k
Result<sigset_t> ThreadYsqlSignalMaskBlock() {
57
1.99k
  return ThreadSignalMaskBlock(kYsqlHandledSignals);
58
1.99k
}
59
60
} // namespace yb