From c05e00039f6bbbdace5c76f8b60d5ca252b11576 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 15 Aug 2009 22:11:26 +0100 Subject: [PATCH] some el cheapo handle release --- config.h | 6 +++--- quark.c | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index fb7e9be..1a0ca62 100644 --- a/config.h +++ b/config.h @@ -1,11 +1,11 @@ /* quark configuration */ -static const char servername[] = "127.0.0.1"; +static const char servername[] = "192.168.1.66"; static const char serverport[] = "80"; static const char docroot[] = "."; static const char docindex[] = "index.html"; -static const char user[] = "www-data"; -static const char group[] = "www-data"; +static const char user[] = "nobody"; +static const char group[] = "nobody"; static const MimeType servermimes[] = { { "html", "text/html; charset=UTF-8" }, diff --git a/quark.c b/quark.c index 82519af..d4429e3 100644 --- a/quark.c +++ b/quark.c @@ -300,13 +300,18 @@ request(void) { void serve(int fd) { int result; + unsigned int timeout = 1; socklen_t salen; struct sockaddr sa; salen = sizeof sa; while(running) { - if((cfd = accept(fd, &sa, &salen)) == -1) - break; + if((cfd = accept(fd, &sa, &salen)) == -1) { + /* el cheapo socket release */ + fprintf(stderr, "%s: cannot accept(), sleep %u seconds\n", tstamp(), timeout); + sleep(timeout++); + continue; + } if(fork() == 0) { close(fd); name[0] = 0; @@ -319,12 +324,21 @@ serve(int fd) { close(cfd); exit(EXIT_SUCCESS); } + timeout = 1; } fprintf(stdout, "%s: shutting down\n", tstamp()); } void sighandler(int sig) { + static const char *signame[64] = { + [SIGHUP] = "SIGHUP", + [SIGINT] = "SIGINT", + [SIGQUIT] = "SIGQUIT", + [SIGABRT] = "SIGABRT", + [SIGTERM] = "SIGTERM", + [SIGCHLD] = "SIGCHLD" + }; switch(sig) { default: break; case SIGHUP: @@ -332,6 +346,7 @@ sighandler(int sig) { case SIGQUIT: case SIGABRT: case SIGTERM: + fprintf(stderr, "%s: received signal %s, closing down\n", tstamp(), signame[sig] ? signame[sig] : ""); close(fd); running = 0; break; @@ -372,6 +387,7 @@ main(int argc, char *argv[]) { /* init */ setbuf(stdout, NULL); /* unbuffered stdout */ + setbuf(stderr, NULL); /* unbuffered stdout */ memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM;