pstore2
signal_helpers.hpp
Go to the documentation of this file.
1 //===- include/pstore/os/signal_helpers.hpp ---------------*- mode: C++ -*-===//
2 //* _ _ _ _ *
3 //* ___(_) __ _ _ __ __ _| | | |__ ___| |_ __ ___ _ __ ___ *
4 //* / __| |/ _` | '_ \ / _` | | | '_ \ / _ \ | '_ \ / _ \ '__/ __| *
5 //* \__ \ | (_| | | | | (_| | | | | | | __/ | |_) | __/ | \__ \ *
6 //* |___/_|\__, |_| |_|\__,_|_| |_| |_|\___|_| .__/ \___|_| |___/ *
7 //* |___/ |_| *
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
12 // information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //===----------------------------------------------------------------------===//
16 
18 
19 #ifndef PSTORE_OS_SIGNAL_HELPERS_HPP
20 #define PSTORE_OS_SIGNAL_HELPERS_HPP
21 
22 #include <cerrno>
23 #include <csignal>
24 
25 namespace pstore {
26 
27  // A simple RAII class which preserves the value of errno. It's needed in the signal handler to
28  // ensure that we don't splat the value that the in-flight code may depend upon.
29  class errno_saver {
30  public:
31  errno_saver () noexcept
32  : old_{errno} {
33  errno = 0;
34  }
35  errno_saver (errno_saver const &) = delete;
36  ~errno_saver () noexcept { errno = old_; }
37  errno_saver & operator= (errno_saver const &) = delete;
38 
39  private:
40  int const old_;
41  };
42 
43  using signal_function = void (*) (int);
44  signal_function register_signal_handler (int signo, signal_function func);
45 
46 } // namespace pstore
47 
48 #endif // PSTORE_OS_SIGNAL_HELPERS_HPP
Definition: nonpod2.cpp:40
Definition: signal_helpers.hpp:29