You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
5.8 KiB

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