File: signals.cpp

package info (click to toggle)
entropybroker 2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,600 kB
  • sloc: cpp: 14,386; sh: 934; makefile: 188; java: 148; perl: 12
file content (72 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <execinfo.h>

#include "error.h"

static int signal_hup = 0, signal_exit = 0;

void signal_handler(int sig)
{
	if (sig == SIGHUP)
		signal_hup = 1;

	if (sig == SIGTERM || sig == SIGQUIT || sig == SIGINT)
		signal_exit = 1;

	if (sig == SIGBUS)
		error_exit("hardware issue, terminating");

	if (sig == SIGUSR2)
		exit(0);

	signal(sig, signal_handler);
}

int is_SIGHUP(void)
{
	return signal_hup;
}

void reset_SIGHUP(void)
{
	signal_hup = 0;
}

int is_SIGEXIT(void)
{
	return signal_exit;
}

#ifdef HELGRIND
void sigsegv_handler(int sig)
{
	void *trace[128];
	int trace_size = backtrace(trace, 128);
	char **messages = backtrace_symbols(trace, trace_size);
	fprintf(stderr, "SIGSEGV\n");
	for(int index=0; index<trace_size; ++index)
		fprintf(stderr, "%d %s\n", index, messages[index]);

	exit(1);
}
#endif

void set_signal_handlers(void)
{
	signal(SIGPIPE, SIG_IGN);

	signal(SIGHUP, signal_handler);
	signal(SIGBUS, signal_handler);

	signal(SIGTERM, signal_handler);
	signal(SIGQUIT, signal_handler);
	signal(SIGINT , signal_handler);

	signal(SIGUSR2, signal_handler);

#ifdef HELGRIND
	signal(SIGSEGV, sigsegv_handler);
#endif
}