geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
POSIXSignal.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef POSIXSIGNAL_HPP_INCLUDE
7 #define POSIXSIGNAL_HPP_INCLUDE
8 
9 #include <signal.h>
10 #include <memory>
11 #include <set>
12 
13 namespace geopm
14 {
16  {
17  public:
20  struct m_info_s {
21  int signo; // siginfo_t::si_signo; /* Signal number */
22  int value; // siginfo_t::si_value; /* Signal value */
23  int pid; // siginfo_t::si_pid; /* Sending process ID */
24  };
25 
26  POSIXSignal() = default;
27  virtual ~POSIXSignal() = default;
32  static std::unique_ptr<POSIXSignal> make_unique(void);
33 
43  virtual sigset_t make_sigset(const std::set<int> &signal_set) const = 0;
44 
52  virtual m_info_s reduce_info(const siginfo_t &info) const = 0;
53 
54  //------------------------------------------------------------------
55  // Functions below here are wrappers around signal(7)
56  // functions. They differ only in the conversion of error
57  // return values into raised geopm::Exceptions based on
58  // errno value.
59  // ------------------------------------------------------------------
60 
68  virtual int sig_wait_info(const sigset_t *sigset,
69  siginfo_t *info) const = 0;
70 
78  virtual int sig_timed_wait(const sigset_t *sigset, siginfo_t *info,
79  const struct timespec *timeout) const = 0;
80 
87  virtual void sig_queue(pid_t pid, int sig,
88  int value) const = 0;
89 
101  virtual void sig_action(int signum, const struct sigaction *act,
102  struct sigaction *oldact) const = 0;
103 
111  virtual void sig_proc_mask(int how, const sigset_t *sigset,
112  sigset_t *oldset) const = 0;
113 
122  virtual void sig_suspend(const sigset_t *mask) const = 0;
123  };
124 
126  {
127  public:
128  POSIXSignalImp() = default;
129  virtual ~POSIXSignalImp() = default;
130  sigset_t make_sigset(const std::set<int> &signal_set) const override;
131  m_info_s reduce_info(const siginfo_t &info) const override;
132  int sig_wait_info(const sigset_t *sigset,
133  siginfo_t *info) const override;
134  int sig_timed_wait(const sigset_t *sigset, siginfo_t *info,
135  const struct timespec *timeout) const override;
136  void sig_queue(pid_t pid, int sig, int value) const override;
137  void sig_action(int signum, const struct sigaction *act,
138  struct sigaction *oldact) const override;
139  void sig_proc_mask(int how, const sigset_t *sigset,
140  sigset_t *oldset) const override;
141  void sig_suspend(const sigset_t *mask) const override;
142  private:
143  void check_return(int err, const std::string &func_name) const;
144  };
145 }
146 
147 #endif
Definition: POSIXSignal.hpp:16
virtual int sig_timed_wait(const sigset_t *sigset, siginfo_t *info, const struct timespec *timeout) const =0
Wrapper for sigtimedwait(2) that converts errors into Exceptions.
virtual ~POSIXSignal()=default
static std::unique_ptr< POSIXSignal > make_unique(void)
Factory method for POSIXSignal interface.
Definition: POSIXSignal.cpp:16
virtual int sig_wait_info(const sigset_t *sigset, siginfo_t *info) const =0
Wrapper for sigwaitinfo(2) that converts errors into Exceptions.
virtual void sig_action(int signum, const struct sigaction *act, struct sigaction *oldact) const =0
Wrapper for sigaction(2) that converts errors into Exceptions.
virtual void sig_queue(pid_t pid, int sig, int value) const =0
Wrapper for sigqueue(3) that converts errors into Exceptions.
virtual void sig_suspend(const sigset_t *mask) const =0
Wrapper for sigsuspend(2) that converts errors into Exceptions.
virtual sigset_t make_sigset(const std::set< int > &signal_set) const =0
Create a sigset_t from a set of signal numbers.
virtual m_info_s reduce_info(const siginfo_t &info) const =0
Extract the signal number, signal value integer and sending PID from a siginfo_t struct to simplify m...
virtual void sig_proc_mask(int how, const sigset_t *sigset, sigset_t *oldset) const =0
Wrapper for sigprocmask(2) that converts errors into Exceptions.
POSIXSignal()=default
Definition: POSIXSignal.hpp:126
m_info_s reduce_info(const siginfo_t &info) const override
Extract the signal number, signal value integer and sending PID from a siginfo_t struct to simplify m...
Definition: POSIXSignal.cpp:33
void sig_proc_mask(int how, const sigset_t *sigset, sigset_t *oldset) const override
Wrapper for sigprocmask(2) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:70
void sig_suspend(const sigset_t *mask) const override
Wrapper for sigsuspend(2) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:75
int sig_wait_info(const sigset_t *sigset, siginfo_t *info) const override
Wrapper for sigwaitinfo(2) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:42
void sig_queue(pid_t pid, int sig, int value) const override
Wrapper for sigqueue(3) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:57
void sig_action(int signum, const struct sigaction *act, struct sigaction *oldact) const override
Wrapper for sigaction(2) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:64
int sig_timed_wait(const sigset_t *sigset, siginfo_t *info, const struct timespec *timeout) const override
Wrapper for sigtimedwait(2) that converts errors into Exceptions.
Definition: POSIXSignal.cpp:49
sigset_t make_sigset(const std::set< int > &signal_set) const override
Create a sigset_t from a set of signal numbers.
Definition: POSIXSignal.cpp:21
virtual ~POSIXSignalImp()=default
Definition: Agg.cpp:20
Reduced information set from siginfo_t struct defined in signal.h.
Definition: POSIXSignal.hpp:20
int signo
Definition: POSIXSignal.hpp:21
int pid
Definition: POSIXSignal.hpp:23
int value
Definition: POSIXSignal.hpp:22