|
@@ -0,0 +1,216 @@
|
|
1
|
+From ea651877c0bb6e129f52eb592cea3b10b2e3347b Mon Sep 17 00:00:00 2001
|
|
2
|
+From: Tobias Brunner <tobias@strongswan.org>
|
|
3
|
+Date: Thu, 19 Nov 2015 11:21:48 +0100
|
|
4
|
+Subject: [PATCH] sigwaitinfo() may fail with EINTR if an unblocked signal not
|
|
5
|
+ in the set is received
|
|
6
|
+
|
|
7
|
+ #1213.
|
|
8
|
+---
|
|
9
|
+ src/charon-cmd/charon-cmd.c | 9 ++++-----
|
|
10
|
+ src/charon-nm/charon-nm.c | 9 ++++-----
|
|
11
|
+ src/charon-systemd/charon-systemd.c | 9 ++++-----
|
|
12
|
+ src/charon-tkm/src/charon-tkm.c | 9 ++++-----
|
|
13
|
+ src/charon/charon.c | 11 +++++------
|
|
14
|
+ src/conftest/conftest.c | 2 +-
|
|
15
|
+ src/frontends/osx/charon-xpc/charon-xpc.c | 7 ++++---
|
|
16
|
+ src/libfast/fast_dispatcher.c | 6 +++++-
|
|
17
|
+ src/libstrongswan/utils/utils.c | 5 ++++-
|
|
18
|
+ 9 files changed, 35 insertions(+), 32 deletions(-)
|
|
19
|
+
|
|
20
|
+diff --git a/src/charon-cmd/charon-cmd.c b/src/charon-cmd/charon-cmd.c
|
|
21
|
+index b8f943f..d3b31cc 100644
|
|
22
|
+--- a/src/charon-cmd/charon-cmd.c
|
|
23
|
++++ b/src/charon-cmd/charon-cmd.c
|
|
24
|
+@@ -115,6 +115,10 @@ static int run()
|
|
25
|
+ sig = sigwaitinfo(&set, NULL);
|
|
26
|
+ if (sig == -1)
|
|
27
|
+ {
|
|
28
|
++ if (errno == EINTR)
|
|
29
|
++ { /* ignore signals we didn't wait for */
|
|
30
|
++ continue;
|
|
31
|
++ }
|
|
32
|
+ DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
|
33
|
+ return 1;
|
|
34
|
+ }
|
|
35
|
+@@ -152,11 +156,6 @@ static int run()
|
|
36
|
+ charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
|
|
37
|
+ return 1;
|
|
38
|
+ }
|
|
39
|
+- default:
|
|
40
|
+- {
|
|
41
|
+- DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
|
|
42
|
+- break;
|
|
43
|
+- }
|
|
44
|
+ }
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+diff --git a/src/charon-nm/charon-nm.c b/src/charon-nm/charon-nm.c
|
|
48
|
+index 1773e7c..fb090e5 100644
|
|
49
|
+--- a/src/charon-nm/charon-nm.c
|
|
50
|
++++ b/src/charon-nm/charon-nm.c
|
|
51
|
+@@ -85,6 +85,10 @@ static void run()
|
|
52
|
+ sig = sigwaitinfo(&set, NULL);
|
|
53
|
+ if (sig == -1)
|
|
54
|
+ {
|
|
55
|
++ if (errno == EINTR)
|
|
56
|
++ { /* ignore signals we didn't wait for */
|
|
57
|
++ continue;
|
|
58
|
++ }
|
|
59
|
+ DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
|
60
|
+ return;
|
|
61
|
+ }
|
|
62
|
+@@ -102,11 +106,6 @@ static void run()
|
|
63
|
+ charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
|
|
64
|
+ return;
|
|
65
|
+ }
|
|
66
|
+- default:
|
|
67
|
+- {
|
|
68
|
+- DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
|
|
69
|
+- break;
|
|
70
|
+- }
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+diff --git a/src/charon-systemd/charon-systemd.c b/src/charon-systemd/charon-systemd.c
|
|
75
|
+index f302d45..4286cde 100644
|
|
76
|
+--- a/src/charon-systemd/charon-systemd.c
|
|
77
|
++++ b/src/charon-systemd/charon-systemd.c
|
|
78
|
+@@ -254,6 +254,10 @@ static int run()
|
|
79
|
+ sig = sigwaitinfo(&set, NULL);
|
|
80
|
+ if (sig == -1)
|
|
81
|
+ {
|
|
82
|
++ if (errno == EINTR)
|
|
83
|
++ { /* ignore signals we didn't wait for */
|
|
84
|
++ continue;
|
|
85
|
++ }
|
|
86
|
+ DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
|
87
|
+ return SS_RC_INITIALIZATION_FAILED;
|
|
88
|
+ }
|
|
89
|
+@@ -265,11 +269,6 @@ static int run()
|
|
90
|
+ charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
|
|
91
|
+ return 0;
|
|
92
|
+ }
|
|
93
|
+- default:
|
|
94
|
+- {
|
|
95
|
+- DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
|
|
96
|
+- break;
|
|
97
|
+- }
|
|
98
|
+ }
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+diff --git a/src/charon-tkm/src/charon-tkm.c b/src/charon-tkm/src/charon-tkm.c
|
|
102
|
+index 52d82f3..3923c8a 100644
|
|
103
|
+--- a/src/charon-tkm/src/charon-tkm.c
|
|
104
|
++++ b/src/charon-tkm/src/charon-tkm.c
|
|
105
|
+@@ -104,6 +104,10 @@ static void run()
|
|
106
|
+ sig = sigwaitinfo(&set, NULL);
|
|
107
|
+ if (sig == -1)
|
|
108
|
+ {
|
|
109
|
++ if (errno == EINTR)
|
|
110
|
++ { /* ignore signals we didn't wait for */
|
|
111
|
++ continue;
|
|
112
|
++ }
|
|
113
|
+ DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
|
114
|
+ return;
|
|
115
|
+ }
|
|
116
|
+@@ -121,11 +125,6 @@ static void run()
|
|
117
|
+ charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
|
|
118
|
+ return;
|
|
119
|
+ }
|
|
120
|
+- default:
|
|
121
|
+- {
|
|
122
|
+- DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
|
|
123
|
+- break;
|
|
124
|
+- }
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+ }
|
|
128
|
+diff --git a/src/charon/charon.c b/src/charon/charon.c
|
|
129
|
+index f03b6e1..4c2a9a4 100644
|
|
130
|
+--- a/src/charon/charon.c
|
|
131
|
++++ b/src/charon/charon.c
|
|
132
|
+@@ -98,7 +98,7 @@ static void run()
|
|
133
|
+ {
|
|
134
|
+ sigset_t set;
|
|
135
|
+
|
|
136
|
+- /* handle SIGINT, SIGHUP ans SIGTERM in this handler */
|
|
137
|
++ /* handle SIGINT, SIGHUP and SIGTERM in this handler */
|
|
138
|
+ sigemptyset(&set);
|
|
139
|
+ sigaddset(&set, SIGINT);
|
|
140
|
+ sigaddset(&set, SIGHUP);
|
|
141
|
+@@ -112,6 +112,10 @@ static void run()
|
|
142
|
+ sig = sigwaitinfo(&set, NULL);
|
|
143
|
+ if (sig == -1)
|
|
144
|
+ {
|
|
145
|
++ if (errno == EINTR)
|
|
146
|
++ { /* ignore signals we didn't wait for */
|
|
147
|
++ continue;
|
|
148
|
++ }
|
|
149
|
+ DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
|
150
|
+ return;
|
|
151
|
+ }
|
|
152
|
+@@ -144,11 +148,6 @@ static void run()
|
|
153
|
+ charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
|
|
154
|
+ return;
|
|
155
|
+ }
|
|
156
|
+- default:
|
|
157
|
+- {
|
|
158
|
+- DBG1(DBG_DMN, "unknown signal %d received. Ignored", sig);
|
|
159
|
+- break;
|
|
160
|
+- }
|
|
161
|
+ }
|
|
162
|
+ }
|
|
163
|
+ }
|
|
164
|
+diff --git a/src/conftest/conftest.c b/src/conftest/conftest.c
|
|
165
|
+index 9348b64..edfe0ca 100644
|
|
166
|
+--- a/src/conftest/conftest.c
|
|
167
|
++++ b/src/conftest/conftest.c
|
|
168
|
+@@ -565,7 +565,7 @@ int main(int argc, char *argv[])
|
|
169
|
+ sigaddset(&set, SIGTERM);
|
|
170
|
+ sigprocmask(SIG_BLOCK, &set, NULL);
|
|
171
|
+
|
|
172
|
+- while ((sig = sigwaitinfo(&set, NULL)) != -1)
|
|
173
|
++ while ((sig = sigwaitinfo(&set, NULL)) != -1 || errno == EINTR)
|
|
174
|
+ {
|
|
175
|
+ switch (sig)
|
|
176
|
+ {
|
|
177
|
+diff --git a/src/libfast/fast_dispatcher.c b/src/libfast/fast_dispatcher.c
|
|
178
|
+index b4c6ce3..66a2ee5 100644
|
|
179
|
+--- a/src/libfast/fast_dispatcher.c
|
|
180
|
++++ b/src/libfast/fast_dispatcher.c
|
|
181
|
+@@ -21,6 +21,7 @@
|
|
182
|
+ #include <fcgiapp.h>
|
|
183
|
+ #include <signal.h>
|
|
184
|
+ #include <unistd.h>
|
|
185
|
++#include <errno.h>
|
|
186
|
+
|
|
187
|
+ #include <utils/debug.h>
|
|
188
|
+ #include <threading/thread.h>
|
|
189
|
+@@ -389,7 +390,10 @@ METHOD(fast_dispatcher_t, waitsignal, void,
|
|
190
|
+ sigaddset(&set, SIGTERM);
|
|
191
|
+ sigaddset(&set, SIGHUP);
|
|
192
|
+ sigprocmask(SIG_BLOCK, &set, NULL);
|
|
193
|
+- sigwaitinfo(&set, NULL);
|
|
194
|
++ while (sigwaitinfo(&set, NULL) == -1 && errno == EINTR)
|
|
195
|
++ {
|
|
196
|
++ /* wait for signal */
|
|
197
|
++ }
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ METHOD(fast_dispatcher_t, destroy, void,
|
|
201
|
+diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c
|
|
202
|
+index 4e86165..40cb43d 100644
|
|
203
|
+--- a/src/libstrongswan/utils/utils.c
|
|
204
|
++++ b/src/libstrongswan/utils/utils.c
|
|
205
|
+@@ -124,7 +124,10 @@ void wait_sigint()
|
|
206
|
+ sigaddset(&set, SIGTERM);
|
|
207
|
+
|
|
208
|
+ sigprocmask(SIG_BLOCK, &set, NULL);
|
|
209
|
+- sigwaitinfo(&set, NULL);
|
|
210
|
++ while (sigwaitinfo(&set, NULL) == -1 && errno == EINTR)
|
|
211
|
++ {
|
|
212
|
++ /* wait for signal */
|
|
213
|
++ }
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ #ifndef HAVE_SIGWAITINFO
|