1 //
2 // This file is part of libyacurs.
3 // Copyright (C) 2013 Rafael Ostertag
4 //
5 // This program is free software: you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see
17 // <http://www.gnu.org/licenses/>.
18 //
19 //
20 // $Id: area.h 5021 2013-04-12 07:17:47Z rafisol $
21
22 #include <cerrno>
23 #include <cstring>
24
25 #include "sigaction.h"
26 #include "yacursex.h"
27
28 using namespace YACURS::INTERNAL;
29
30 //
31 // Private
32 //
33
34 //
35 // Protected
36 //
37
38 //
39 // Public
40 //
41
Sigaction(int signo,sig_handler hndlr,sigset_t & mask)42 Sigaction::Sigaction(int signo, sig_handler hndlr, sigset_t& mask)
43 : _signo(signo) {
44 #ifdef SA_SIGINFO
45 _current_action.sa_sigaction = hndlr;
46 _current_action.sa_flags = SA_SIGINFO;
47 #else
48 _current_action.sa_handler = hndlr;
49 _current_action.sa_flags = 0;
50 #endif
51
52 std::memcpy(&_current_action.sa_mask, &mask, sizeof(sigset_t));
53
54 if (sigaction(_signo, &_current_action, &_saved_action) != 0)
55 throw EXCEPTIONS::SystemError(errno);
56 }
57
~Sigaction()58 Sigaction::~Sigaction() { sigaction(_signo, &_saved_action, 0); }
59
reset() const60 void Sigaction::reset() const {
61 // We don't save the old action, since we already have that done
62 // in the ctor.
63 if (sigaction(_signo, &_current_action, 0) != 0)
64 throw EXCEPTIONS::SystemError(errno);
65 }
66