author | viric <viriketo@gmail.com> |
Wed, 19 Oct 2016 22:09:35 +0200 | |
changeset 352 | 387687433b1e |
parent 282 | 835551fcecb7 |
permissions | -rw-r--r-- |
102
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
1 |
/* |
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
2 |
Task Spooler - a task queue system for the unix user |
267 | 3 |
Copyright (C) 2007-2009 LluĂs Batlle i Rossell |
102
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
4 |
|
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
5 |
Please find the license in the provided COPYING file. |
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
6 |
*/ |
95 | 7 |
#include <signal.h> |
138 | 8 |
#include <stdio.h> |
95 | 9 |
#include <stdlib.h> /* for NULL */ |
146 | 10 |
#include <sys/time.h> /* for NULL */ |
138 | 11 |
#include "main.h" |
95 | 12 |
|
13 |
/* Some externs refer to this variable */ |
|
14 |
static sigset_t normal_sigmask; |
|
15 |
||
138 | 16 |
/* as extern in execute.c */ |
17 |
int signals_child_pid; /* 0, not set. otherwise, set. */ |
|
18 |
||
95 | 19 |
void ignore_sigpipe() |
20 |
{ |
|
21 |
sigset_t set; |
|
22 |
||
23 |
sigemptyset(&set); |
|
24 |
sigaddset(&set, SIGPIPE); |
|
25 |
sigprocmask(SIG_BLOCK, &set, &normal_sigmask); |
|
26 |
} |
|
27 |
||
28 |
void restore_sigmask() |
|
29 |
{ |
|
30 |
sigprocmask(SIG_SETMASK, &normal_sigmask, NULL); |
|
31 |
} |
|
32 |
||
138 | 33 |
void sigint_handler(int s) |
34 |
{ |
|
35 |
if (signals_child_pid) |
|
36 |
{ |
|
37 |
kill(signals_child_pid, SIGINT); |
|
38 |
} else |
|
39 |
{ |
|
139 | 40 |
/* ts client killed by SIGINT */ |
138 | 41 |
exit(1); |
42 |
} |
|
43 |
} |
|
44 |
||
45 |
void block_sigint() |
|
46 |
{ |
|
47 |
sigset_t set; |
|
48 |
||
49 |
sigemptyset(&set); |
|
50 |
sigaddset(&set, SIGINT); |
|
51 |
/* ignore_sigpipe() will always be called first, and |
|
52 |
* only that sets the normal_sigmask. */ |
|
53 |
sigprocmask(SIG_BLOCK, &set, 0); |
|
54 |
} |
|
55 |
||
56 |
void unblock_sigint_and_install_handler() |
|
57 |
{ |
|
58 |
sigset_t set; |
|
59 |
struct sigaction act; |
|
60 |
||
61 |
/* Install the handler */ |
|
62 |
act.sa_handler = sigint_handler; |
|
63 |
sigemptyset(&act.sa_mask); |
|
64 |
act.sa_flags = 0; |
|
65 |
sigaction(SIGINT, &act, 0); |
|
66 |
||
67 |
/* Unblock the signal */ |
|
68 |
sigemptyset(&set); |
|
69 |
sigaddset(&set, SIGINT); |
|
70 |
/* ignore_sigpipe() will always be called first, and |
|
71 |
* only that sets the normal_sigmask. */ |
|
72 |
sigprocmask(SIG_UNBLOCK, &set, 0); |
|
73 |
} |