-
Notifications
You must be signed in to change notification settings - Fork 24
/
signals.c
executable file
·73 lines (61 loc) · 1.55 KB
/
signals.c
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
/*
Task Spooler - a task queue system for the unix user
Copyright (C) 2007-2009 Lluís Batlle i Rossell
Please find the license in the provided COPYING file.
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h> /* for NULL */
#include <sys/time.h> /* for NULL */
#include "main.h"
/* Some externs refer to this variable */
static sigset_t normal_sigmask;
/* as extern in execute.c */
int signals_child_pid; /* 0, not set. otherwise, set. */
void ignore_sigpipe()
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGPIPE);
sigprocmask(SIG_BLOCK, &set, &normal_sigmask);
}
void restore_sigmask()
{
sigprocmask(SIG_SETMASK, &normal_sigmask, NULL);
}
void sigint_handler(int s)
{
if (signals_child_pid)
{
kill(signals_child_pid, SIGINT);
} else
{
/* ts client killed by SIGINT */
exit(1);
}
}
void block_sigint()
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
/* ignore_sigpipe() will always be called first, and
* only that sets the normal_sigmask. */
sigprocmask(SIG_BLOCK, &set, 0);
}
void unblock_sigint_and_install_handler()
{
sigset_t set;
struct sigaction act;
/* Install the handler */
act.sa_handler = sigint_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, 0);
/* Unblock the signal */
sigemptyset(&set);
sigaddset(&set, SIGINT);
/* ignore_sigpipe() will always be called first, and
* only that sets the normal_sigmask. */
sigprocmask(SIG_UNBLOCK, &set, 0);
}