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/>.
35 static void usage(FILE *out)
37 fprintf(out, "usage: httimed [-h] [-t TIMEOUT] CHILD [ARGS...]\n");
40 int main(int argc, char **argv)
49 while((c = getopt(argc, argv, "+ht:")) >= 0) {
57 fprintf(stderr, "httimed: timeout must be positive\n");
63 if(argc - optind < 1) {
67 if((ch = stdmkchild(argv + optind, NULL, NULL)) < 0) {
68 flog(LOG_ERR, "httimed: could not fork child: %s", strerror(errno));
73 memset(pfd, 0, sizeof(pfd));
75 pfd[0].events = POLLIN;
77 pfd[1].events = POLLHUP;
78 if((ret = poll(pfd, 2, (t + 1 - (time(NULL) - lreq)) * 1000)) < 0) {
80 flog(LOG_ERR, "httimed: error in poll: %s", strerror(errno));
86 if((fd = recvreq(0, &req)) < 0) {
89 flog(LOG_ERR, "httimed: error in recvreq: %s", strerror(errno));
92 if(sendreq(ch, req, fd)) {
93 flog(LOG_ERR, "httimed: could not pass request to child: %s", strerror(errno));
99 if(pfd[1].revents & POLLHUP)