diff options
author | Christian Hesse <mail@eworm.de> | 2016-10-11 12:48:53 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2016-10-11 12:48:53 +0200 |
commit | 40457d78c69f6376148dce073531f8d36762c8fa (patch) | |
tree | b5b4a413121451c21424d2ba579fa725d3f53e5f /pacredir.c | |
parent | bb6c031e0668d5265e507232b1377b141b0703e2 (diff) | |
download | pacredir-40457d78c69f6376148dce073531f8d36762c8fa.tar.gz pacredir-40457d78c69f6376148dce073531f8d36762c8fa.tar.zst |
Be more verbose about badtime, simplify condition
Diffstat (limited to 'pacredir.c')
-rw-r--r-- | pacredir.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -97,7 +97,7 @@ update: request.service = &tmphosts->pacserve; } else if (strcmp(type, PACDBSERVE) == 0) { tmphosts->pacdbserve.online = 1; - tmphosts->pacdbserve.port = (port > 0? port : PORT_PACDBSERVE); + tmphosts->pacdbserve.port = (port > 0 ? port : PORT_PACDBSERVE); request.service = &tmphosts->pacdbserve; } @@ -369,13 +369,17 @@ static int ahc_echo(void * cls, /* try to find a server with most recent file */ while (tmphosts->host != NULL) { + struct services *service = (dbfile ? &tmphosts->pacdbserve : &tmphosts->pacserve); + time_t badtime = service->badtime + service->badcount * BADTIME; + /* skip host if offline or had a bad request within last BADTIME seconds */ - if ((dbfile == 1 && - (tmphosts->pacdbserve.online == 0 || - tmphosts->pacdbserve.badtime + tmphosts->pacdbserve.badcount * BADTIME > tv.tv_sec)) || - (dbfile == 0 && - (tmphosts->pacserve.online == 0 || - tmphosts->pacserve.badtime + tmphosts->pacserve.badcount * BADTIME > tv.tv_sec))) { + if (service->online == 0 || badtime > tv.tv_sec) { + /* write the time to buffer ctime, then strip the line break */ + ctime_r(&badtime, ctime); + ctime[strlen(ctime) - 1] = '\0'; + + write_log(stdout, "Service %s on host %s is marked bad until %s, skipping\n", + dbfile ? PACDBSERVE : PACSERVE, tmphosts->host, ctime); tmphosts = tmphosts->next; continue; } @@ -411,7 +415,7 @@ static int ahc_echo(void * cls, request->last_modified = 0; if (verbose > 0) - write_log(stdout, "Trying %s\n", request->url); + write_log(stdout, "Trying: %s\n", request->url); if ((error = pthread_create(&tid[req_count], NULL, get_http_code, (void *)request)) != 0) write_log(stderr, "Could not run thread number %d, errno %d\n", req_count, error); |