diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-03-11 22:46:39 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-03-11 22:46:39 +0100 |
commit | 6e6f8a68e5d0aa51dc906151aa8c62de3e907ae8 (patch) | |
tree | 4e353b86aead5ab07b926233603a37c34539229c | |
parent | 4333359de7d637667ddd61e6aeebc034429199a1 (diff) | |
download | cgi-6e6f8a68e5d0aa51dc906151aa8c62de3e907ae8.zip |
Add request timeout
-rwxr-xr-x | main.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -78,6 +78,8 @@ exit $? # */ #define CGI_CGIT "/usr/lib/cgit/cgit.cgi" enum { + REQUEST_TIMEOUT = 2, + DEFAULT_SCALE = 100, DEFAULT_WIDTH = 42, @@ -3277,10 +3279,19 @@ void setup_theme_cookie(c8 const *cookie, c8 const *query) { } } +void on_alarm(int s) { + fflush(stdout); + printf("Status: 408 Request Timeout\r\n"); + exit(0); +} + i32 main(i32 argc, c8 **argv) { (void) argc; (void) argv; + signal(SIGALRM, on_alarm); + alarm(REQUEST_TIMEOUT); + FILE *_in = freopen(NULL, "rb", stdin); FILE *_out = freopen(NULL, "wb", stdout); (void) _in; @@ -3306,7 +3317,7 @@ i32 main(i32 argc, c8 **argv) { strlen(content_type) > MAX_CONTENT_TYPE_SIZE || (!str_eq(request_method, NULL, "GET", NULL) && !str_eq(request_method, NULL, "POST", NULL))) { - printf("Status: 500 Internal Server Error 1\r\n"); + printf("Status: 500 Internal Server Error\r\n"); return 0; } @@ -3329,7 +3340,7 @@ i32 main(i32 argc, c8 **argv) { for (i64 i = 0; i < (i64)(sizeof redirects / sizeof *redirects); ++i) if (str_eq_with_slash(document_uri, redirects[i].alias)) { if (redirects[i].url == NULL) { - printf("Status: 500 Internal Server Error 2\r\n"); + printf("Status: 500 Internal Server Error\r\n"); return 0; } |