2
* Copyright © 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored By: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
19
#include "mir/signal_blocker.h"
21
#include <system_error>
23
#include <boost/exception/all.hpp>
25
mir::SignalBlocker::SignalBlocker()
28
sigfillset(&all_signals);
30
if (auto error = pthread_sigmask(SIG_BLOCK, &all_signals, &previous_set))
31
BOOST_THROW_EXCEPTION((
32
std::system_error{error,
33
std::system_category(),
34
"Failed to block signals"}));
37
mir::SignalBlocker::~SignalBlocker() noexcept(false)
39
if (auto error = pthread_sigmask(SIG_SETMASK, &previous_set, nullptr))
41
if (!std::uncaught_exception())
43
BOOST_THROW_EXCEPTION((std::system_error{error,
44
std::system_category(),
45
"Failed to restore signal mask"}));