From: Fredrik Tolf Date: Thu, 13 Feb 2014 02:29:44 +0000 (+0100) Subject: Added the `httrcall' program. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=6caaee997035b71ef7bd830c3c7894e47e59ec85;p=ashd.git Added the `httrcall' program. --- diff --git a/src/.gitignore b/src/.gitignore index 582f3e7..1ecc66e 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -12,3 +12,4 @@ /errlogger /psendfile /httimed +/httrcall diff --git a/src/Makefile.am b/src/Makefile.am index 5c4f895..5422e74 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = dirplex bin_PROGRAMS = htparser sendfile callcgi patplex userplex htls \ callscgi accesslog htextauth callfcgi multifscgi \ - errlogger httimed psendfile + errlogger httimed psendfile httrcall htparser_SOURCES = htparser.c htparser.h plaintcp.c ssl-gnutls.c diff --git a/src/httrcall.c b/src/httrcall.c new file mode 100644 index 0000000..0d7d845 --- /dev/null +++ b/src/httrcall.c @@ -0,0 +1,95 @@ +/* + ashd - A Sane HTTP Daemon + Copyright (C) 2008 Fredrik Tolf + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include + +static char **prog; + +static void serve(struct hthead *req, int fd) +{ + if(stdforkserve(prog, req, fd, NULL, NULL) < 0) + simpleerror(fd, 500, "Server Error", "The server appears to be overloaded."); +} + +static void chldhandler(int sig) +{ + pid_t pid; + int st; + + while((pid = waitpid(-1, &st, WNOHANG)) > 0) { + if(WCOREDUMP(st)) + flog(LOG_WARNING, "child process %i dumped core", pid); + } +} + +static void usage(FILE *out) +{ + fprintf(out, "usage: httrcall [-h] PROGRAM [ARGS...]\n"); +} + +int main(int argc, char **argv) +{ + int c; + struct hthead *req; + int fd; + + while((c = getopt(argc, argv, "+h")) >= 0) { + switch(c) { + case 'h': + usage(stdout); + exit(0); + default: + usage(stderr); + exit(1); + } + } + if(argc < optind - 1) { + usage(stderr); + exit(1); + } + prog = argv + optind; + signal(SIGCHLD, chldhandler); + while(1) { + if((fd = recvreq(0, &req)) < 0) { + if(errno == EINTR) + continue; + if(errno != 0) + flog(LOG_ERR, "recvreq: %s", strerror(errno)); + break; + } + serve(req, fd); + freehthead(req); + close(fd); + } + return(0); +}