From b9d6c8ce98689db2c6facc576b71f6d7f2643f17 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 30 Oct 2012 19:10:55 -0600 Subject: [PATCH] Quit needing CFLAGS --- .gitignore | 2 ++ Makefile | 10 ++++++---- eris.c | 28 +++++++++++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1214681 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +version.h diff --git a/Makefile b/Makefile index 8f904d8..1ff388e 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ -VERSION := $(shell head -n 1 CHANGES | tr -d :) - -CFLAGS = -DFNORD='"eris/$(VERSION)"' -Wall -Werror +CFLAGS = -Wall -Werror all: eris eris: eris.o strings.o mime.o timerfc.o +eris.o: version.h +version.h: CHANGES + awk -F : 'NR==1 {printf("const char *FNORD = \"eris/%s\";\n", $$1);}' $< > $@ + test: eris sh ./test.sh clean: - rm -f *.[oa] eris + rm -f *.[oa] version.h eris diff --git a/eris.c b/eris.c index e12ee78..1e6ef34 100644 --- a/eris.c +++ b/eris.c @@ -25,6 +25,7 @@ #include "strings.h" #include "mime.h" #include "timerfc.h" +#include "version.h" #ifdef __linux__ # include @@ -143,7 +144,7 @@ void header(unsigned int code, const char *httpcomment) { printf("HTTP/1.%d %u %s\r\n", http_version, code, httpcomment); - printf("Server: " FNORD "\r\n"); + printf("Server: %s\r\n", FNORD); printf("Connection: %s\r\n", keepalive?"keep-alive":"close"); } @@ -265,7 +266,7 @@ parse_options(int argc, char *argv[]) redirect = 1; break; case 'v': - printf(FNORD "\n"); + printf("%s\n", FNORD); exit(0); case 'h': default: @@ -319,14 +320,15 @@ cgi_child(const char *relpath) env("CONTENT_TYPE", content_type); } - /* Change to CGI's directory */ + /* Try to change to CGI's directory */ { char *delim = strrchr(relpath, '/'); if (delim) { *delim = '\0'; - chdir(relpath); - relpath = delim + 1; + if (0 == chdir(relpath)) { + relpath = delim + 1; + } } } @@ -439,13 +441,23 @@ cgi_parent(int cin, int cout, int passthru) size_t len; char buf[BUFFER_SIZE]; size_t nmemb = min(BUFFER_SIZE, content_length); + char *p = buf; len = fread(buf, 1, nmemb, stdin); if (len < 1) { break; } content_length -= len; - write(cout, buf, len); + + while (len > 0) { + size_t wlen = write(cout, p, len); + + if (wlen == -1) { + break; + } + len -= wlen; + p += wlen; + } } else { close(cout); } @@ -989,7 +1001,9 @@ main(int argc, char *argv[], const char *const *envp) if (! keepalive) { break; } - fchdir(cwd); + if (-1 == fchdir(cwd)) { + break; + } } return 0;