blob: 12d3c835ac3bd545d144acaf52490c677861729c (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/**** POSIX *******************************************************************/
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
/**** RELABSD *****************************************************************/
#include <relabsd/debug.h>
/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/
static int RELABSD_INTERRUPTION_PIPES[2];
static int RELABSD_RUN = 1;
static void interrupt (int unused_mandatory_parameter __attribute__((unused)))
{
RELABSD_RUN = 0;
errno = 0;
if (write(RELABSD_INTERRUPTION_PIPES[1], (void *) "!", (size_t) 1) == -1)
{
RELABSD_ERROR
(
"Unable to signal the interruption to the conversion thread."
" Interruption should still occur following the next input from the"
" physical device. Error: %s.",
strerror(errno)
);
}
}
/******************************************************************************/
/**** EXPORTED FUNCTIONS ******************************************************/
/******************************************************************************/
int relabsd_server_keep_running (void)
{
return RELABSD_RUN;
}
void relabsd_server_interrupt (void)
{
interrupt(0);
}
int relabsd_server_initialize_signal_handlers (void)
{
RELABSD_S_DEBUG(RELABSD_DEBUG_PROGRAM_FLOW, "Setting signal handlers.");
errno = 0;
if (pipe(RELABSD_INTERRUPTION_PIPES) == -1)
{
RELABSD_FATAL
(
"Unable to create an unnamed pipe for the interruption handling: %s",
strerror(errno)
);
return -1;
}
if (signal(SIGINT, interrupt) == SIG_ERR)
{
RELABSD_S_FATAL("Unable to set the SIGINT signal handler.");
(void) close(RELABSD_INTERRUPTION_PIPES[0]);
(void) close(RELABSD_INTERRUPTION_PIPES[1]);
return -1;
}
if (signal(SIGTERM, interrupt) == SIG_ERR)
{
RELABSD_S_FATAL("Unable to set the SIGTERM signal handler.");
(void) close(RELABSD_INTERRUPTION_PIPES[0]);
(void) close(RELABSD_INTERRUPTION_PIPES[1]);
return -1;
}
return 0;
}
void relabsd_server_finalize_signal_handlers (void)
{
(void) close(RELABSD_INTERRUPTION_PIPES[0]);
(void) close(RELABSD_INTERRUPTION_PIPES[1]);
}
int relabsd_server_get_interruption_file_descriptor (void)
{
return RELABSD_INTERRUPTION_PIPES[0];
}
|