From 9411b044ee37862b90b5da0a18ea4f5984095de4 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 27 Sep 2021 21:36:26 +0000 Subject: Handle KCGI_EXIT gracefully --- image.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/image.c b/image.c index 3abcc2e..573ded1 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); -- cgit 1.4.1