2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
37 struct current *next, *prev;
42 static struct current *running = NULL;
43 static int nrunning = 0, limit = 0;
44 static volatile int exited;
46 static void checkexit(int block)
53 while((pid = waitpid(-1, &st, block?0:WNOHANG)) > 0) {
55 flog(LOG_WARNING, "child process %i dumped core", pid);
56 for(rec = running; rec != NULL; rec = rec->next) {
59 rec->next->prev = rec->prev;
61 rec->prev->next = rec->next;
72 static void serve(struct hthead *req, int fd)
77 while((limit > 0) && (nrunning >= limit))
79 if((new = stdforkserve(prog, req, fd, NULL, NULL)) < 0) {
80 simpleerror(fd, 500, "Server Error", "The server appears to be overloaded.");
92 static void chldhandler(int sig)
97 static void usage(FILE *out)
99 fprintf(out, "usage: httrcall [-h] [-l LIMIT] PROGRAM [ARGS...]\n");
102 int main(int argc, char **argv)
108 while((c = getopt(argc, argv, "+hl:")) >= 0) {
114 limit = atoi(optarg);
121 if(argc < optind - 1) {
125 prog = argv + optind;
126 sigaction(SIGCHLD, &(struct sigaction) {
127 .sa_handler = chldhandler,
132 if((fd = recvreq(0, &req)) < 0) {
136 flog(LOG_ERR, "recvreq: %s", strerror(errno));