commit c05e00039f6bbbdace5c76f8b60d5ca252b11576
parent c621fad3de34a890b0ea27ae20c789c0de7c9d84
Author: Anselm R Garbe <anselm@garbe.us>
Date: Sat, 15 Aug 2009 22:11:26 +0100
some el cheapo handle release
Diffstat:
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git 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
@@ -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;