diff options
Diffstat (limited to 'image.c')
-rw-r--r-- | image.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/image.c b/image.c index 80e2567..584eb4c 100644 --- a/image.c +++ b/image.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018, 2019 C. McEnroe <june@causal.agency> +/* Copyright (C) 2018, 2019 June McEnroe <june@causal.agency> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -27,10 +27,6 @@ #include <unistd.h> #include <zlib.h> -#ifdef __FreeBSD__ -#include <sys/capsicum.h> -#endif - #ifdef HAVE_KCGI #include <sys/types.h> #include <stdarg.h> @@ -204,16 +200,21 @@ static int streamWrite(void *cookie, const char *buf, int len) { static void worker(void) { struct kfcgi *fcgi; - enum kcgi_err error = khttp_fcgi_init( + int error = khttp_fcgi_init( &fcgi, Keys, KeysLen, Pages, PagesLen, PageTile ); if (error) errkcgi(EX_CONFIG, error, "khttp_fcgi_init"); - for (;;) { - struct kreq req; - error = khttp_fcgi_parse(fcgi, &req); - if (error) errkcgi(EX_DATAERR, error, "khttp_fcgi_parse"); +#ifdef __OpenBSD__ + error = pledge("stdio recvfd", NULL); + if (error) err(EX_OSERR, "pledge"); +#endif + for ( + struct kreq req; + !(error = khttp_fcgi_parse(fcgi, &req)); + khttp_free(&req) + ) { uint32_t tileX = TileInitX; uint32_t tileY = TileInitY; if (req.fieldmap[KeyX]) { @@ -226,18 +227,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 }; @@ -246,10 +247,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 */ @@ -276,13 +276,21 @@ int main(int argc, char *argv[]) { fontLoad(fontPath); tilesMap(dataPath); -#ifdef __FreeBSD__ - int error = cap_enter(); - if (error) err(EX_OSERR, "cap_enter"); +#ifdef __OpenBSD__ + if (kcgi) { + int error = pledge("stdio unix sendfd recvfd proc", NULL); + if (error) err(EX_OSERR, "pledge"); + } else { + int error = pledge("stdio", NULL); + if (error) err(EX_OSERR, "pledge"); + } #endif #ifdef HAVE_KCGI - if (kcgi) worker(); + if (kcgi) { + worker(); + return EX_OK; + } #endif render(stdout, tileX, tileY); |