YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
902
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
902
  sigset_t mask;
25
902
  sigemptyset(&mask);
26
4.51k
  for (int sig : signals_to_block) {
27
4.51k
    int err = sigaddset(&mask, sig);
28
4.51k
    if (err != 0) {
29
0
      return STATUS(InternalError, "sigaddset failed", Errno(errno));
30
0
    }
31
4.51k
  }
32
33
902
  sigset_t old_mask;
34
902
  int err = pthread_sigmask(SIG_BLOCK, &mask, &old_mask);
35
902
  return (err == 0
36
902
      ? Result<sigset_t>(old_mask)
37
0
      : STATUS(InternalError, "SIG_BLOCK failed", Errno(err)));
38
902
}
39
40
902
Status ThreadSignalMaskRestore(sigset_t old_mask) {
41
902
  int err = pthread_sigmask(SIG_SETMASK, &old_mask, NULL /* oldset */);
42
902
  return (err == 0
43
902
      ? Status::OK()
44
0
      : STATUS(InternalError, "SIG_SETMASK failed", Errno(err)));
45
902
}
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
902
Result<sigset_t> ThreadYsqlSignalMaskBlock() {
57
902
  return ThreadSignalMaskBlock(kYsqlHandledSignals);
58
902
}
59
60
} // namespace yb