summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authorGravatar default2022-09-29 12:50:50 +0200
committerGravatar default2022-09-29 12:50:50 +0200
commit80d1700f6a82707a4b5ffdce2fa8b1ec7d118f65 (patch)
treeb1d70f6080ec845161a6df8b8e3151b5f95fc9ff /httpd.c
parentReplace kill(getpid()) with raise(). (diff)
downloadsnac2-80d1700f6a82707a4b5ffdce2fa8b1ec7d118f65.tar.gz
snac2-80d1700f6a82707a4b5ffdce2fa8b1ec7d118f65.tar.xz
snac2-80d1700f6a82707a4b5ffdce2fa8b1ec7d118f65.zip
Added some signal control.
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/httpd.c b/httpd.c
index c6959e6..a57b4c1 100644
--- a/httpd.c
+++ b/httpd.c
@@ -10,6 +10,8 @@
10 10
11#include "snac.h" 11#include "snac.h"
12 12
13#include <setjmp.h>
14
13/* susie.png */ 15/* susie.png */
14const char *susie = 16const char *susie =
15 "iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC" 17 "iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC"
@@ -188,6 +190,15 @@ void httpd_connection(int rs)
188} 190}
189 191
190 192
193static jmp_buf on_break;
194
195
196void term_handler(int s)
197{
198 longjmp(on_break, 1);
199}
200
201
191void httpd(void) 202void httpd(void)
192/* starts the server */ 203/* starts the server */
193{ 204{
@@ -205,11 +216,22 @@ void httpd(void)
205 216
206 srv_running = 1; 217 srv_running = 1;
207 218
219 signal(SIGPIPE, SIG_IGN);
220 signal(SIGTERM, term_handler);
221 signal(SIGINT, term_handler);
222
208 srv_log(xs_fmt("httpd start %s:%d", address, port)); 223 srv_log(xs_fmt("httpd start %s:%d", address, port));
209 224
210 for (;;) { 225 if (setjmp(on_break) == 0) {
211 httpd_connection(rs); 226 for (;;) {
227 httpd_connection(rs);
228 }
212 } 229 }
213 230
231 srv_running = 0;
232
233 /* wait for the helper thread to end */
234 /* ... */
235
214 srv_log(xs_fmt("httpd stop %s:%d", address, port)); 236 srv_log(xs_fmt("httpd stop %s:%d", address, port));
215} 237}