diff options
author | default <nobody@localhost> | 2022-09-29 12:50:50 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-29 12:50:50 +0200 |
commit | 80d1700f6a82707a4b5ffdce2fa8b1ec7d118f65 (patch) | |
tree | b1d70f6080ec845161a6df8b8e3151b5f95fc9ff /httpd.c | |
parent | aabdbe1deef21bde913a63738fd5020b7ee35df0 (diff) |
Added some signal control.
Diffstat (limited to 'httpd.c')
-rw-r--r-- | httpd.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -10,6 +10,8 @@ #include "snac.h" +#include <setjmp.h> + /* susie.png */ const char *susie = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC" @@ -188,6 +190,15 @@ void httpd_connection(int rs) } +static jmp_buf on_break; + + +void term_handler(int s) +{ + longjmp(on_break, 1); +} + + void httpd(void) /* starts the server */ { @@ -205,11 +216,22 @@ void httpd(void) srv_running = 1; + signal(SIGPIPE, SIG_IGN); + signal(SIGTERM, term_handler); + signal(SIGINT, term_handler); + srv_log(xs_fmt("httpd start %s:%d", address, port)); - for (;;) { - httpd_connection(rs); + if (setjmp(on_break) == 0) { + for (;;) { + httpd_connection(rs); + } } + srv_running = 0; + + /* wait for the helper thread to end */ + /* ... */ + srv_log(xs_fmt("httpd stop %s:%d", address, port)); } |