diff options
author | June McEnroe <june@causal.agency> | 2021-09-27 21:36:26 +0000 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-09-27 21:36:26 +0000 |
commit | 5651d93e474f835073e7c5e66fc34c5d90271b4c (patch) | |
tree | 4a11ee614d24a11f4d73b01eafa5c2e423289610 | |
parent | Call msync(2) after modifying tiles (diff) | |
download | torus-5651d93e474f835073e7c5e66fc34c5d90271b4c.tar.gz torus-5651d93e474f835073e7c5e66fc34c5d90271b4c.zip |
Handle KCGI_EXIT gracefully
Diffstat (limited to '')
-rw-r--r-- | image.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/image.c b/image.c index 5e7fee7..8bdce53 100644 --- a/image.c +++ b/image.c @@ -214,11 +214,11 @@ static void worker(void) { if (error) err(EX_OSERR, "pledge"); #endif - for (;;) { + for ( struct kreq req; - error = khttp_fcgi_parse(fcgi, &req); - if (error) errkcgi(EX_DATAERR, error, "khttp_fcgi_parse"); - + !(error = khttp_fcgi_parse(fcgi, &req)); + khttp_free(&req) + ) { uint32_t tileX = TileInitX; uint32_t tileY = TileInitY; if (req.fieldmap[KeyX]) { @@ -231,18 +231,18 @@ static void worker(void) { error = khttp_head( &req, kresps[KRESP_STATUS], "%s", khttps[KHTTP_200] ); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_head"); error = khttp_head( &req, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_IMAGE_PNG] ); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_head"); // XXX: kcgi never enables compression for FastCGI. error = khttp_body(&req); - if (error == KCGI_HUP) goto next; + if (error == KCGI_HUP) continue; if (error) errkcgi(EX_IOERR, error, "khttp_body"); struct Stream cookie = { .req = &req }; @@ -251,10 +251,9 @@ static void worker(void) { render(stream, tileX, tileY); fclose(stream); - -next: - khttp_free(&req); } + if (error != KCGI_EXIT) errkcgi(EX_PROTOCOL, error, "khttp_fcgi_parse"); + khttp_fcgi_free(fcgi); } #endif /* HAVE_KCGI */ @@ -297,7 +296,10 @@ int main(int argc, char *argv[]) { #endif #ifdef HAVE_KCGI - if (kcgi) worker(); + if (kcgi) { + worker(); + return EX_OK; + } #endif render(stdout, tileX, tileY); |