X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=src%2Fhttimed.c;fp=src%2Fhttimed.c;h=dc8ba99d4ccf28fc6fed5da172cb60044e5ba8e1;hp=2c939c54eb940131be13f679654aad69bafad0a2;hb=bcad6b0c48d516ddc920b52f06083ceaa242e1ca;hpb=589987f8218c9aa61d65f582a3b3e1bbd32bda81 diff --git a/src/httimed.c b/src/httimed.c index 2c939c5..dc8ba99 100644 --- a/src/httimed.c +++ b/src/httimed.c @@ -23,6 +23,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -39,21 +40,21 @@ static void usage(FILE *out) int main(int argc, char **argv) { - int c, t, ret; + int c, timeout, ret; int ch, fd; struct hthead *req; struct pollfd pfd[2]; time_t lreq, now; - t = 300; + timeout = 300; while((c = getopt(argc, argv, "+ht:")) >= 0) { switch(c) { case 'h': usage(stdout); exit(0); case 't': - t = atoi(optarg); - if(t < 1) { + timeout = atoi(optarg); + if(timeout < 1) { fprintf(stderr, "httimed: timeout must be positive\n"); exit(1); } @@ -75,7 +76,7 @@ int main(int argc, char **argv) pfd[0].events = POLLIN; pfd[1].fd = ch; pfd[1].events = POLLHUP; - if((ret = poll(pfd, 2, (t + 1 - (time(NULL) - lreq)) * 1000)) < 0) { + if((ret = poll(pfd, 2, (timeout < 0)?-1:((timeout + 1 - (time(NULL) - lreq)) * 1000))) < 0) { if(errno != EINTR) { flog(LOG_ERR, "httimed: error in poll: %s", strerror(errno)); exit(1); @@ -96,10 +97,10 @@ int main(int argc, char **argv) freehthead(req); close(fd); } - if(pfd[1].revents & POLLHUP) - break; - if(now - lreq > t) - break; + if((pfd[1].revents & POLLHUP) || (now - lreq > timeout)) { + timeout = -1; + shutdown(0, SHUT_RDWR); + } lreq = now; } return(0);