author | viric@llimona |
Mon, 12 Nov 2007 09:57:46 +0100 | |
changeset 140 | 0b99d94818d1 |
parent 139 | e5c0fccdb233 |
child 146 | 5e689cb593aa |
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 |
27b0f0e44de8
Added copyright headers to the new files. I always forget that.
viric@llimona
parents:
95
diff
changeset
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
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 */ |
138 | 10 |
#include "main.h" |
95 | 11 |
|
12 |
/* Some externs refer to this variable */ |
|
13 |
static sigset_t normal_sigmask; |
|
14 |
||
138 | 15 |
/* as extern in execute.c */ |
16 |
int signals_child_pid; /* 0, not set. otherwise, set. */ |
|
17 |
||
95 | 18 |
void ignore_sigpipe() |
19 |
{ |
|
20 |
sigset_t set; |
|
21 |
||
22 |
sigemptyset(&set); |
|
23 |
sigaddset(&set, SIGPIPE); |
|
24 |
sigprocmask(SIG_BLOCK, &set, &normal_sigmask); |
|
25 |
} |
|
26 |
||
27 |
void restore_sigmask() |
|
28 |
{ |
|
29 |
sigprocmask(SIG_SETMASK, &normal_sigmask, NULL); |
|
30 |
} |
|
31 |
||
138 | 32 |
void sigint_handler(int s) |
33 |
{ |
|
34 |
if (signals_child_pid) |
|
35 |
{ |
|
36 |
kill(signals_child_pid, SIGINT); |
|
37 |
} else |
|
38 |
{ |
|
139 | 39 |
/* ts client killed by SIGINT */ |
138 | 40 |
exit(1); |
41 |
} |
|
42 |
} |
|
43 |
||
44 |
void block_sigint() |
|
45 |
{ |
|
46 |
sigset_t set; |
|
47 |
||
48 |
sigemptyset(&set); |
|
49 |
sigaddset(&set, SIGINT); |
|
50 |
/* ignore_sigpipe() will always be called first, and |
|
51 |
* only that sets the normal_sigmask. */ |
|
52 |
sigprocmask(SIG_BLOCK, &set, 0); |
|
53 |
} |
|
54 |
||
55 |
void unblock_sigint_and_install_handler() |
|
56 |
{ |
|
57 |
sigset_t set; |
|
58 |
struct sigaction act; |
|
59 |
||
60 |
/* Install the handler */ |
|
61 |
act.sa_handler = sigint_handler; |
|
62 |
sigemptyset(&act.sa_mask); |
|
63 |
act.sa_flags = 0; |
|
64 |
sigaction(SIGINT, &act, 0); |
|
65 |
||
66 |
/* Unblock the signal */ |
|
67 |
sigemptyset(&set); |
|
68 |
sigaddset(&set, SIGINT); |
|
69 |
/* ignore_sigpipe() will always be called first, and |
|
70 |
* only that sets the normal_sigmask. */ |
|
71 |
sigprocmask(SIG_UNBLOCK, &set, 0); |
|
72 |
} |