[hackers] [quark] some el cheapo handle release || Anselm R Garbe

From: <hg_AT_suckless.org>
Date: Sat, 15 Aug 2009 21:11:34 +0000 (UTC)

changeset: 3:f34cc4c3d37e
tag: tip
user: Anselm R Garbe <anselm_AT_garbe.us>
date: Sat Aug 15 22:11:26 2009 +0100
files: config.h quark.c
description:
some el cheapo handle release

diff -r dfc94a7d6dab -r f34cc4c3d37e config.h
--- a/config.h Sat Aug 15 20:01:53 2009 +0100
+++ b/config.h Sat Aug 15 22:11:26 2009 +0100
@@ -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 -r dfc94a7d6dab -r f34cc4c3d37e quark.c
--- a/quark.c Sat Aug 15 20:01:53 2009 +0100
+++ b/quark.c Sat Aug 15 22:11:26 2009 +0100
@@ -300,13 +300,18 @@
 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 @@
                         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 @@
         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 @@
 
         /* 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;
Received on Sat Aug 15 2009 - 21:11:34 UTC

This archive was generated by hypermail 2.2.0 : Sun Aug 16 2009 - 14:19:06 UTC