forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal_restore_posix.cpp
More file actions
38 lines (29 loc) · 1.09 KB
/
signal_restore_posix.cpp
File metadata and controls
38 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "signal_restore_posix.h"
#include <signal.h>
#include <string.h>
// arraysize borrowed from base/macros.h
template <typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
namespace {
const int signals_to_restore[] =
{SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP, SIGPIPE};
struct sigaction signal_handlers[arraysize(signals_to_restore)];
} // namespace
void BackupSignalHandlers() {
struct sigaction sigact;
for (unsigned i = 0; i < arraysize(signals_to_restore); ++i) {
memset(&sigact, 0, sizeof(sigact));
sigaction(signals_to_restore[i], NULL, &sigact);
signal_handlers[i] = sigact;
}
}
void RestoreSignalHandlers() {
for (unsigned i = 0; i < arraysize(signals_to_restore); ++i) {
sigaction(signals_to_restore[i], &signal_handlers[i], NULL);
}
}