Module Name: src
Committed By: mrg
Date: Sat Apr 18 21:22:03 UTC 2009
Modified Files:
src/libexec/httpd: CHANGES auth-bozo.c bozohttpd.8 bozohttpd.c
bozohttpd.h cgi-bozo.c daemon-bozo.c
Log Message:
merge bozohttpd 20090418. remove a couple of minor do-nothing local
changes that don't need to cause conflicts.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/libexec/httpd/CHANGES
cvs rdiff -u -r1.6 -r1.7 src/libexec/httpd/auth-bozo.c
cvs rdiff -u -r1.12 -r1.13 src/libexec/httpd/bozohttpd.8 \
src/libexec/httpd/bozohttpd.c src/libexec/httpd/cgi-bozo.c
cvs rdiff -u -r1.9 -r1.10 src/libexec/httpd/bozohttpd.h
cvs rdiff -u -r1.5 -r1.6 src/libexec/httpd/daemon-bozo.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/libexec/httpd/CHANGES
diff -u src/libexec/httpd/CHANGES:1.3 src/libexec/httpd/CHANGES:1.4
--- src/libexec/httpd/CHANGES:1.3 Sat Apr 18 07:48:02 2009
+++ src/libexec/httpd/CHANGES Sat Apr 18 21:22:03 2009
@@ -1,4 +1,10 @@
-$eterna: CHANGES,v 1.65 2009/04/18 05:36:04 mrg Exp $
+$eterna: CHANGES,v 1.67 2009/04/18 11:42:39 mrg Exp $
+
+changes since bozohttpd 20090417:
+ o avoid dying in daemon mode for some uncommon, but recoverable, errors
+ o close leaking file descriptors for CGI and daemon mode
+ o handle poll errors properly
+ o don't try to handle more than one request per process yet
changes since bozohttpd 20080303:
o make bozohttpd internally more modular, preparing the way
Index: src/libexec/httpd/auth-bozo.c
diff -u src/libexec/httpd/auth-bozo.c:1.6 src/libexec/httpd/auth-bozo.c:1.7
--- src/libexec/httpd/auth-bozo.c:1.6 Sat Apr 18 07:38:40 2009
+++ src/libexec/httpd/auth-bozo.c Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-/* $NetBSD: auth-bozo.c,v 1.6 2009/04/18 07:38:40 mrg Exp $ */
+/* $NetBSD: auth-bozo.c,v 1.7 2009/04/18 21:22:03 mrg Exp $ */
-/* $eterna: auth-bozo.c,v 1.12 2009/04/17 22:52:19 mrg Exp $ */
+/* $eterna: auth-bozo.c,v 1.13 2009/04/18 07:38:56 mrg Exp $ */
/*
* Copyright (c) 1997-2009 Matthew R. Green
Index: src/libexec/httpd/bozohttpd.8
diff -u src/libexec/httpd/bozohttpd.8:1.12 src/libexec/httpd/bozohttpd.8:1.13
--- src/libexec/httpd/bozohttpd.8:1.12 Sat Apr 18 12:35:51 2009
+++ src/libexec/httpd/bozohttpd.8 Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-.\" $NetBSD: bozohttpd.8,v 1.12 2009/04/18 12:35:51 wiz Exp $
+.\" $NetBSD: bozohttpd.8,v 1.13 2009/04/18 21:22:03 mrg Exp $
.\"
-.\" $eterna: bozohttpd.8,v 1.84 2009/04/18 01:48:18 mrg Exp $
+.\" $eterna: bozohttpd.8,v 1.87 2009/04/18 20:53:58 mrg Exp $
.\"
.\" Copyright (c) 1997-2009 Matthew R. Green
.\" All rights reserved.
@@ -141,6 +141,9 @@
.Ar myname ,
which defaults to the name returned by
.Xr gethostname 3 .
+Only the last
+.Fl i
+option is used.
.It Fl M Ar suffix type encoding encoding11
This option adds a new entry to the table that converts file suffixes to
content type and encoding.
@@ -450,7 +453,7 @@
and regular code audits.
This manual documents
.Nm
-version 20090417.
+version 20090418.
.Sh AUTHORS
.Nm
was written by Matthew R. Green
Index: src/libexec/httpd/bozohttpd.c
diff -u src/libexec/httpd/bozohttpd.c:1.12 src/libexec/httpd/bozohttpd.c:1.13
--- src/libexec/httpd/bozohttpd.c:1.12 Sat Apr 18 07:28:24 2009
+++ src/libexec/httpd/bozohttpd.c Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-/* $NetBSD: bozohttpd.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */
+/* $NetBSD: bozohttpd.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */
-/* $eterna: bozohttpd.c,v 1.152 2009/04/18 05:36:04 mrg Exp $ */
+/* $eterna: bozohttpd.c,v 1.155 2009/04/18 20:53:58 mrg Exp $ */
/*
* Copyright (c) 1997-2009 Matthew R. Green
@@ -109,7 +109,7 @@
#define INDEX_HTML "index.html"
#endif
#ifndef SERVER_SOFTWARE
-#define SERVER_SOFTWARE "bozohttpd/20090417"
+#define SERVER_SOFTWARE "bozohttpd/20090418"
#endif
#ifndef DIRECT_ACCESS_FILE
#define DIRECT_ACCESS_FILE ".bzdirect"
@@ -532,7 +532,7 @@
clean_request(request);
return (0);
}
- } while (bflag);
+ } while (bflag && 0);
return (0);
}
@@ -1454,8 +1454,10 @@
if (auth_check(request, newfile))
goto bad_done;
- if (strlen(newfile))
+ if (strlen(newfile)) {
+ free(request->hr_file);
request->hr_file = newfile;
+ }
if (process_cgi(request))
return 0;
Index: src/libexec/httpd/cgi-bozo.c
diff -u src/libexec/httpd/cgi-bozo.c:1.12 src/libexec/httpd/cgi-bozo.c:1.13
--- src/libexec/httpd/cgi-bozo.c:1.12 Sat Apr 18 07:28:24 2009
+++ src/libexec/httpd/cgi-bozo.c Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-/* $NetBSD: cgi-bozo.c,v 1.12 2009/04/18 07:28:24 mrg Exp $ */
+/* $NetBSD: cgi-bozo.c,v 1.13 2009/04/18 21:22:03 mrg Exp $ */
-/* $eterna: cgi-bozo.c,v 1.28 2009/04/18 05:36:04 mrg Exp $ */
+/* $eterna: cgi-bozo.c,v 1.30 2009/04/18 12:39:28 mrg Exp $ */
/*
* Copyright (c) 1997-2009 Matthew R. Green
@@ -43,6 +43,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <unistd.h>
#include <netinet/in.h>
@@ -121,6 +122,7 @@
cgihandler = NULL;
command = NULL;
info = NULL;
+
len = strlen(url);
if (auth_check(request, url + 1))
@@ -180,9 +182,6 @@
auth_cgi_count(request) +
(request->hr_serverport && *request->hr_serverport ? 1 : 0);
- debug((DEBUG_FAT,
- "process_cgi: envpsize `%d'", envpsize));
-
envp = bozomalloc(sizeof(*envp) * envpsize);
for (ix = 0; ix < envpsize; ix++)
envp[ix] = NULL;
@@ -209,7 +208,7 @@
spsetenv(env, headp->h_value, curenvp++);
free(env);
}
-
+
#ifndef _PATH_DEFPATH
#define _PATH_DEFPATH "/usr/bin:/bin"
#endif
@@ -263,12 +262,13 @@
close(sv[0]);
dup2(sv[1], STDIN_FILENO);
dup2(sv[1], STDOUT_FILENO);
-
- debug((DEBUG_FAT, "process_cgi: going exec %s, %s %s %s",
- path, argv[0], strornull(argv[1]), strornull(argv[2])));
+ close(2);
+ close(sv[1]);
+ closelog();
if (-1 == execve(path, argv, envp))
- error(1, "child exec failed: %s", path);
+ error(1, "child exec failed: %s: %s",
+ path, strerror(errno));
/* NOT REACHED */
error(1, "child execve returned?!");
}
Index: src/libexec/httpd/bozohttpd.h
diff -u src/libexec/httpd/bozohttpd.h:1.9 src/libexec/httpd/bozohttpd.h:1.10
--- src/libexec/httpd/bozohttpd.h:1.9 Sat Apr 18 07:37:08 2009
+++ src/libexec/httpd/bozohttpd.h Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-/* $NetBSD: bozohttpd.h,v 1.9 2009/04/18 07:37:08 mrg Exp $ */
+/* $NetBSD: bozohttpd.h,v 1.10 2009/04/18 21:22:03 mrg Exp $ */
-/* $eterna: bozohttpd.h,v 1.25 2009/04/18 05:36:04 mrg Exp $ */
+/* $eterna: bozohttpd.h,v 1.26 2009/04/18 07:38:56 mrg Exp $ */
/*
* Copyright (c) 1997-2009 Matthew R. Green
Index: src/libexec/httpd/daemon-bozo.c
diff -u src/libexec/httpd/daemon-bozo.c:1.5 src/libexec/httpd/daemon-bozo.c:1.6
--- src/libexec/httpd/daemon-bozo.c:1.5 Sat Apr 18 07:28:24 2009
+++ src/libexec/httpd/daemon-bozo.c Sat Apr 18 21:22:03 2009
@@ -1,6 +1,6 @@
-/* $NetBSD: daemon-bozo.c,v 1.5 2009/04/18 07:28:24 mrg Exp $ */
+/* $NetBSD: daemon-bozo.c,v 1.6 2009/04/18 21:22:03 mrg Exp $ */
-/* $eterna: daemon-bozo.c,v 1.13 2009/04/17 22:52:20 mrg Exp $ */
+/* $eterna: daemon-bozo.c,v 1.16 2009/04/18 13:06:45 mrg Exp $ */
/*
* Copyright (c) 1997-2009 Matthew R. Green
@@ -120,12 +120,7 @@
daemon_fork()
{
struct pollfd *fds = NULL;
-
- while (bflag) {
- struct sockaddr_storage ss;
- socklen_t slen;
- int fd;
- int i;
+ int i, j;
#ifndef POLLRDNORM
#define POLLRDNORM 0
@@ -136,14 +131,23 @@
#ifndef INFTIM
#define INFTIM -1
#endif
- if (fds == NULL) {
- fds = bozomalloc(nsock * sizeof *fds);
- for (i = 0; i < nsock; i++) {
- fds[i].events = POLLIN | POLLPRI | POLLRDNORM |
- POLLRDBAND | POLLERR;
- fds[i].fd = sock[i];
- }
- }
+
+ fds = bozomalloc(nsock * sizeof *fds);
+ for (i = 0; i < nsock; i++) {
+ if (sock[i] == -1)
+ continue;
+ fds[i].events = POLLIN | POLLPRI | POLLRDNORM |
+ POLLRDBAND | POLLERR;
+ fds[i].fd = sock[i];
+ }
+
+ while (bflag) {
+ struct sockaddr_storage ss;
+ socklen_t slen;
+ int fd;
+
+ if (nsock == 0)
+ exit(0);
/*
* wait for a connection, then fork() and return NULL in
@@ -153,25 +157,53 @@
*/
again:
if (poll(fds, nsock, INFTIM) == -1) {
- if (errno != EINTR)
+ /* fail on programmer errors */
+ if (errno == EFAULT ||
+ errno == EINVAL)
error(1, "poll: %s", strerror(errno));
+
+ /* sleep on some temporary kernel failures */
+ if (errno == ENOMEM ||
+ errno == EAGAIN)
+ sleep(1);
+
goto again;
}
for (i = 0; i < nsock; i++) {
if (fds[i].revents & (POLLNVAL|POLLERR|POLLHUP)) {
- warning("poll on fd %d: %s", fds[i].fd,
- strerror(errno));
- continue;
+ warning("poll on fd %d pid %d revents %d: %s",
+ fds[i].fd, getpid(), fds[i].revents, strerror(errno));
+ warning("nsock = %d", nsock);
+ close(sock[i]);
+ nsock--;
+ warning("nsock now = %d", nsock);
+ /* no sockets left */
+ if (nsock == 0)
+ exit(0);
+ /* last socket; easy case */
+ if (nsock == i)
+ break;
+ memmove(&fds[i], &fds[i+i],
+ (nsock - i) * sizeof(*fds));
+ memmove(&sock[i], &sock[i+i],
+ (nsock - i) * sizeof(*sock));
+ break;
}
if (fds[i].revents == 0)
continue;
slen = sizeof(ss);
- fd = accept(sock[i], (struct sockaddr *)&ss, &slen);
+ fd = accept(fds[i].fd, (struct sockaddr *)&ss, &slen);
if (fd == -1) {
- if (errno != EAGAIN)
+ if (errno == EFAULT ||
+ errno == EINVAL)
error(1, "accept: %s", strerror(errno));
+
+ if (errno == ENOMEM ||
+ errno == EAGAIN)
+ sleep(1);
+
continue;
}
switch (fork()) {
@@ -187,7 +219,11 @@
dup2(fd, 0);
dup2(fd, 1);
/*dup2(fd, 2);*/
+ free(fds);
+ free(sock);
close(fd);
+ for (j = 0; j < nsock; j++)
+ close(sock[j]);
return;
default: /* parent */
@@ -196,6 +232,7 @@
}
}
}
+ free(fds);
}
#endif /* NO_DAEMON_MODE */