This helper is in preparation for adding a second struct check element to struct server.
Signed-off-by: Simon Horman <ho...@verge.net.au> --- src/cfgparse.c | 3 +-- src/checks.c | 45 +++++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index 8119f39..2a70a17 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -4255,9 +4255,8 @@ stats_error_parsing: newsrv->uweight = newsrv->iweight = curproxy->defsrv.iweight; - newsrv->check.health = newsrv->rise; /* up, but will fall down at first failure */ - newsrv->check.status = HCHK_STATUS_INI; + newsrv->check.health = newsrv->rise; /* up, but will fall down at first failure */ newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY; newsrv->check.name = "Health"; newsrv->check.server = newsrv; diff --git a/src/checks.c b/src/checks.c index c7e2345..9642666 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1529,6 +1529,32 @@ static struct task *process_chk(struct task *t) return t; } +static int start_check_task(struct check *check, int mininter, + int nbcheck, int srvpos) +{ + struct task *t; + /* task for the check */ + if ((t = task_new()) == NULL) { + Alert("Starting [%s:%s] check: out of memory.\n", + check->server->proxy->id, check->server->id); + return -1; + } + + check->task = t; + t->process = process_chk; + t->context = check; + + /* check this every ms */ + t->expire = tick_add(now_ms, + MS_TO_TICKS(((mininter && + mininter >= srv_getinter(check)) ? + mininter : srv_getinter(check)) * srvpos / nbcheck)); + check->start = now; + task_queue(t); + + return 0; +} + /* * Start health-check. * Returns 0 if OK, -1 if error, and prints the error in this case. @@ -1589,25 +1615,8 @@ int start_checks() { if (!(s->state & SRV_CHECKED)) continue; - /* one task for the checks */ - if ((t = task_new()) == NULL) { - Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); + if (start_check_task(&s->check, mininter, nbcheck, srvpos++)) return -1; - } - - s->check.task = t; - t->process = process_chk; - t->context = &s->check; - - /* check this every ms */ - t->expire = tick_add(now_ms, - MS_TO_TICKS(((mininter && - mininter >= srv_getinter(&s->check)) ? - mininter : srv_getinter(&s->check)) * srvpos / nbcheck)); - s->check.start = now; - task_queue(t); - - srvpos++; } } return 0; -- 1.7.10.4