diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_loop.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_loop.c | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/src/exchange/taler-exchange-httpd_loop.c b/src/exchange/taler-exchange-httpd_loop.c deleted file mode 100644 index 086fbc874..000000000 --- a/src/exchange/taler-exchange-httpd_loop.c +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of TALER | ||
3 | Copyright (C) 2014--2020 Taler Systems SA | ||
4 | |||
5 | TALER is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU Affero General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | TALER is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU Affero General Public License along with | ||
14 | TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | /** | ||
17 | * @file taler-exchange-httpd_loop.c | ||
18 | * @brief management of our main loop | ||
19 | * @author Florian Dold | ||
20 | * @author Benedikt Mueller | ||
21 | * @author Christian Grothoff | ||
22 | */ | ||
23 | #include "platform.h" | ||
24 | #include <pthread.h> | ||
25 | #include "taler-exchange-httpd_loop.h" | ||
26 | |||
27 | |||
28 | /* ************************* Signal logic ************************** */ | ||
29 | |||
30 | /** | ||
31 | * Pipe used for signaling reloading of our key state. | ||
32 | */ | ||
33 | static int reload_pipe[2] = { -1, -1 }; | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Handle a signal, writing relevant signal numbers to the pipe. | ||
38 | * | ||
39 | * @param signal_number the signal number | ||
40 | */ | ||
41 | static void | ||
42 | handle_signal (int signal_number) | ||
43 | { | ||
44 | char c = (char) signal_number; /* never seen a signal_number > 127 on any platform */ | ||
45 | |||
46 | (void) ! write (reload_pipe[1], | ||
47 | &c, | ||
48 | 1); | ||
49 | /* While one might like to "handle errors" here, even logging via fprintf() | ||
50 | isn't safe inside of a signal handler. So there is nothing we safely CAN | ||
51 | do. OTOH, also very little that can go wrong in practice. Calling _exit() | ||
52 | on errors might be a possibility, but that might do more harm than good. */// | ||
53 | } | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Call #handle_signal() to pass the received signal via | ||
58 | * the control pipe. | ||
59 | */ | ||
60 | static void | ||
61 | handle_sigint (void) | ||
62 | { | ||
63 | handle_signal (SIGINT); | ||
64 | } | ||
65 | |||
66 | |||
67 | /** | ||
68 | * Call #handle_signal() to pass the received signal via | ||
69 | * the control pipe. | ||
70 | */ | ||
71 | static void | ||
72 | handle_sigterm (void) | ||
73 | { | ||
74 | handle_signal (SIGTERM); | ||
75 | } | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Call #handle_signal() to pass the received signal via | ||
80 | * the control pipe. | ||
81 | */ | ||
82 | static void | ||
83 | handle_sighup (void) | ||
84 | { | ||
85 | handle_signal (SIGHUP); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Call #handle_signal() to pass the received signal via | ||
91 | * the control pipe. | ||
92 | */ | ||
93 | static void | ||
94 | handle_sigchld (void) | ||
95 | { | ||
96 | handle_signal (SIGCHLD); | ||
97 | } | ||
98 | |||
99 | |||
100 | int | ||
101 | TEH_loop_run (void) | ||
102 | { | ||
103 | int ret; | ||
104 | |||
105 | ret = 2; | ||
106 | while (2 == ret) | ||
107 | { | ||
108 | char c; | ||
109 | ssize_t res; | ||
110 | |||
111 | errno = 0; | ||
112 | res = read (reload_pipe[0], | ||
113 | &c, | ||
114 | 1); | ||
115 | if ((res < 0) && (EINTR != errno)) | ||
116 | { | ||
117 | GNUNET_break (0); | ||
118 | ret = GNUNET_SYSERR; | ||
119 | break; | ||
120 | } | ||
121 | if (EINTR == errno) | ||
122 | continue; | ||
123 | switch (c) | ||
124 | { | ||
125 | case SIGTERM: | ||
126 | case SIGINT: | ||
127 | /* terminate */ | ||
128 | ret = GNUNET_OK; | ||
129 | break; | ||
130 | case SIGHUP: | ||
131 | /* restart updated binary */ | ||
132 | ret = GNUNET_NO; | ||
133 | break; | ||
134 | #if HAVE_DEVELOPER | ||
135 | case SIGCHLD: | ||
136 | /* running in test-mode, test finished, terminate */ | ||
137 | ret = GNUNET_OK; | ||
138 | break; | ||
139 | #endif | ||
140 | default: | ||
141 | /* unexpected character */ | ||
142 | GNUNET_break (0); | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | return ret; | ||
147 | } | ||
148 | |||
149 | |||
150 | static struct GNUNET_SIGNAL_Context *sigterm; | ||
151 | static struct GNUNET_SIGNAL_Context *sigint; | ||
152 | static struct GNUNET_SIGNAL_Context *sighup; | ||
153 | static struct GNUNET_SIGNAL_Context *sigchld; | ||
154 | |||
155 | |||
156 | int | ||
157 | TEH_loop_init (void) | ||
158 | { | ||
159 | if (0 != pipe (reload_pipe)) | ||
160 | { | ||
161 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | ||
162 | "pipe"); | ||
163 | return GNUNET_SYSERR; | ||
164 | } | ||
165 | sigterm = GNUNET_SIGNAL_handler_install (SIGTERM, | ||
166 | &handle_sigterm); | ||
167 | sigint = GNUNET_SIGNAL_handler_install (SIGINT, | ||
168 | &handle_sigint); | ||
169 | sighup = GNUNET_SIGNAL_handler_install (SIGHUP, | ||
170 | &handle_sighup); | ||
171 | sigchld = GNUNET_SIGNAL_handler_install (SIGCHLD, | ||
172 | &handle_sigchld); | ||
173 | return GNUNET_OK; | ||
174 | } | ||
175 | |||
176 | |||
177 | void | ||
178 | TEH_loop_done (void) | ||
179 | { | ||
180 | if (NULL != sigterm) | ||
181 | { | ||
182 | GNUNET_SIGNAL_handler_uninstall (sigterm); | ||
183 | sigterm = NULL; | ||
184 | } | ||
185 | if (NULL != sigint) | ||
186 | { | ||
187 | GNUNET_SIGNAL_handler_uninstall (sigint); | ||
188 | sigint = NULL; | ||
189 | } | ||
190 | if (NULL != sighup) | ||
191 | { | ||
192 | GNUNET_SIGNAL_handler_uninstall (sighup); | ||
193 | sighup = NULL; | ||
194 | } | ||
195 | if (NULL != sigchld) | ||
196 | { | ||
197 | GNUNET_SIGNAL_handler_uninstall (sigchld); | ||
198 | sigchld = NULL; | ||
199 | } | ||
200 | if (-1 != reload_pipe[0]) | ||
201 | { | ||
202 | GNUNET_break (0 == close (reload_pipe[0])); | ||
203 | GNUNET_break (0 == close (reload_pipe[1])); | ||
204 | reload_pipe[0] = reload_pipe[1] = -1; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | |||
209 | /* end of taler-exchange-httpd_loop.c */ | ||