some el cheapo handle release
This commit is contained in:
parent
c621fad3de
commit
c05e00039f
2 changed files with 21 additions and 5 deletions
6
config.h
6
config.h
|
@ -1,11 +1,11 @@
|
||||||
/* quark configuration */
|
/* 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 serverport[] = "80";
|
||||||
static const char docroot[] = ".";
|
static const char docroot[] = ".";
|
||||||
static const char docindex[] = "index.html";
|
static const char docindex[] = "index.html";
|
||||||
static const char user[] = "www-data";
|
static const char user[] = "nobody";
|
||||||
static const char group[] = "www-data";
|
static const char group[] = "nobody";
|
||||||
|
|
||||||
static const MimeType servermimes[] = {
|
static const MimeType servermimes[] = {
|
||||||
{ "html", "text/html; charset=UTF-8" },
|
{ "html", "text/html; charset=UTF-8" },
|
||||||
|
|
20
quark.c
20
quark.c
|
@ -300,13 +300,18 @@ request(void) {
|
||||||
void
|
void
|
||||||
serve(int fd) {
|
serve(int fd) {
|
||||||
int result;
|
int result;
|
||||||
|
unsigned int timeout = 1;
|
||||||
socklen_t salen;
|
socklen_t salen;
|
||||||
struct sockaddr sa;
|
struct sockaddr sa;
|
||||||
|
|
||||||
salen = sizeof sa;
|
salen = sizeof sa;
|
||||||
while(running) {
|
while(running) {
|
||||||
if((cfd = accept(fd, &sa, &salen)) == -1)
|
if((cfd = accept(fd, &sa, &salen)) == -1) {
|
||||||
break;
|
/* el cheapo socket release */
|
||||||
|
fprintf(stderr, "%s: cannot accept(), sleep %u seconds\n", tstamp(), timeout);
|
||||||
|
sleep(timeout++);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(fork() == 0) {
|
if(fork() == 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
|
@ -319,12 +324,21 @@ serve(int fd) {
|
||||||
close(cfd);
|
close(cfd);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
timeout = 1;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "%s: shutting down\n", tstamp());
|
fprintf(stdout, "%s: shutting down\n", tstamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sighandler(int sig) {
|
sighandler(int sig) {
|
||||||
|
static const char *signame[64] = {
|
||||||
|
[SIGHUP] = "SIGHUP",
|
||||||
|
[SIGINT] = "SIGINT",
|
||||||
|
[SIGQUIT] = "SIGQUIT",
|
||||||
|
[SIGABRT] = "SIGABRT",
|
||||||
|
[SIGTERM] = "SIGTERM",
|
||||||
|
[SIGCHLD] = "SIGCHLD"
|
||||||
|
};
|
||||||
switch(sig) {
|
switch(sig) {
|
||||||
default: break;
|
default: break;
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
|
@ -332,6 +346,7 @@ sighandler(int sig) {
|
||||||
case SIGQUIT:
|
case SIGQUIT:
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
|
fprintf(stderr, "%s: received signal %s, closing down\n", tstamp(), signame[sig] ? signame[sig] : "");
|
||||||
close(fd);
|
close(fd);
|
||||||
running = 0;
|
running = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -372,6 +387,7 @@ main(int argc, char *argv[]) {
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
setbuf(stdout, NULL); /* unbuffered stdout */
|
setbuf(stdout, NULL); /* unbuffered stdout */
|
||||||
|
setbuf(stderr, NULL); /* unbuffered stdout */
|
||||||
memset(&hints, 0, sizeof hints);
|
memset(&hints, 0, sizeof hints);
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
Loading…
Reference in a new issue