cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
signals.cpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
11
13
14#include <algorithm>
15#include <csignal>
16
17#ifndef NSIG
18 #define NSIG (_SIGMAX + 1) /* For QNX */
19#endif
20
22
24{
25 for(std::size_t signal = 0; signal != m_signals_number; ++signal) { sighandler_t hand = std::signal(signal, handler); }
26}
27
28Term::Private::Signals::Signals(std::vector<sighandler_t>& m_han) noexcept
29{
30 const static std::vector<int> ignore{
31#if defined(SIGCONT)
32 SIGCONT,
33#endif
34#if defined(SIGSTOP)
35 SIGSTOP,
36#endif
37#if defined(SIGTSTP)
38 SIGTSTP,
39#endif
40#if defined(SIGTTIN)
41 SIGTTIN,
42#endif
43#if defined(SIGTTOU)
44 SIGTTOU,
45#endif
46 };
47 m_han.reserve(m_signals_number);
48 for(std::size_t signal = 0; signal != m_signals_number; ++signal)
49 {
50 //if(std::find(ignore.begin(),ignore.end(),signal)==ignore.end())
51 //{
52 sighandler_t old = std::signal(signal, SIG_DFL);
53 //sighandler_t dumb=std::signal(signal, old);
54 m_han.push_back(old);
55 //}
56 //else
57 //{
58 // std::signal(signal, SIG_IGN);
59 // m_han.push_back(std::signal(signal, SIG_IGN));
60 // }
61 }
62}
63
64void Term::Private::Signals::reset_and_raise(int sign, std::vector<sighandler_t>& m_han, Term::Terminal& term) noexcept
65{
66 const static std::vector<int> termin{
67#if defined(SIGHUP)
68 SIGHUP,
69#endif
70#if defined(SIGHUP)
71 SIGINT,
72#endif
73#if defined(SIGQUIT)
74 SIGQUIT,
75#endif
76#if defined(SIGQUIT)
77 SIGILL,
78#endif
79#if defined(SIGTRAP)
80 SIGTRAP,
81#endif
82#if defined(SIGTRAP)
83 SIGABRT,
84#endif
85#if defined(SIGIOT)
86 SIGIOT,
87#endif
88#if defined(SIGBUS)
89 SIGBUS,
90#endif
91#if defined(SIGBUS)
92 SIGFPE,
93#endif
94#if defined(SIGKILL)
95 SIGKILL,
96#endif
97#if defined(SIGUSR1)
98 SIGUSR1,
99#endif
100#if defined(SIGSEGV)
101 SIGSEGV,
102#endif
103#if defined(SIGUSR2)
104 SIGUSR2,
105#endif
106#if defined(SIGUSR2)
107 SIGPIPE,
108#endif
109#if defined(SIGALRM)
110 SIGALRM,
111#endif
112#if defined(SIGSTKFLT)
113 SIGSTKFLT,
114#endif
115#if defined(SIGCONT)
116 SIGCONT,
117#endif
118#if defined(SIGXCPU)
119 SIGXCPU,
120#endif
121#if defined(SIGXFSZ)
122 SIGXFSZ,
123#endif
124#if defined(SIGVTALRM)
125 SIGVTALRM,
126#endif
127#if defined(SIGPROF)
128 SIGPROF,
129#endif
130#if defined(SIGPROF)
131 SIGIO,
132#endif
133#if defined(SIGPOLL)
134 SIGPOLL,
135#endif
136#if defined(SIGPWR)
137 SIGPWR,
138#endif
139#if defined(SIGSYS)
140 SIGSYS,
141#endif
142#if defined(SIGUNUSED)
143 SIGUNUSED,
144#endif
145#if defined(SIGUNUSED)
146 SIGUNUSED,
147#endif
148#if defined(SIGTERM)
149 SIGTERM
150#endif
151 };
152 if(std::find(termin.begin(), termin.end(), sign) != termin.end())
153 {
154 sighandler_t old = std::signal(sign, m_han[sign]);
155 old = std::signal(sign, m_han[sign]);
156 term.clean();
157 std::raise(sign);
158 }
159}
static const std::size_t m_signals_number
Definition signals.hpp:21
Signals(std::vector< sighandler_t > &m_han) noexcept
Definition signals.cpp:28
static void reset_and_raise(int sign, std::vector< sighandler_t > &m_han, Term::Terminal &) noexcept
Definition signals.cpp:64
void setHandler(const sighandler_t &handler) noexcept
Definition signals.cpp:23
#define NSIG
Definition signals.cpp:18
void(*)(int) sighandler_t
Definition signals.hpp:14