MEDIUM: cfgparse: Factor out check initialisation

This is in preparation for struct server having two elements
of type struct check.

Signed-off-by: Simon Horman <horms@verge.net.au>
This commit is contained in:
Simon Horman 2013-02-23 15:14:19 +09:00 committed by Willy Tarreau
parent 4a741432be
commit 69d29f996b

View File

@ -1620,6 +1620,34 @@ out:
return err_code;
}
static int init_check(struct check *check, int type, const char * file, int linenum)
{
check->type = type;
/* Allocate buffer for requests... */
if ((check->bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
return ERR_ALERT | ERR_ABORT;
}
check->bi->size = global.tune.chksize;
/* Allocate buffer for responses... */
if ((check->bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
return ERR_ALERT | ERR_ABORT;
}
check->bo->size = global.tune.chksize;
/* Allocate buffer for partial results... */
if ((check->conn = calloc(1, sizeof(struct connection))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum);
return ERR_ALERT | ERR_ABORT;
}
check->conn->t.sock.fd = -1; /* no agent in progress yet */
return 0;
}
int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
{
@ -4273,6 +4301,9 @@ stats_error_parsing:
newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
newsrv->check.status = HCHK_STATUS_INI;
newsrv->check.server = newsrv;
cur_arg = 3;
} else {
newsrv = &curproxy->defsrv;
@ -4832,6 +4863,8 @@ stats_error_parsing:
}
if (do_check) {
int ret;
if (newsrv->trackit) {
Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n",
file, linenum);
@ -4877,33 +4910,14 @@ stats_error_parsing:
goto out;
}
/* Allocate buffer for check requests... */
if ((newsrv->check.bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
newsrv->check.bi->size = global.tune.chksize;
/* Allocate buffer for check responses... */
if ((newsrv->check.bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum);
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
newsrv->check.bo->size = global.tune.chksize;
/* Allocate buffer for partial check results... */
if ((newsrv->check.conn = calloc(1, sizeof(struct connection))) == NULL) {
Alert("parsing [%s:%d] : out of memory while allocating check connection.\n", file, linenum);
err_code |= ERR_ALERT | ERR_ABORT;
ret = init_check(&newsrv->check,
curproxy->options2 & PR_O2_CHK_ANY,
file, linenum);
if (ret) {
err_code |= ret;
goto out;
}
newsrv->check.conn->t.sock.fd = -1; /* no check in progress yet */
newsrv->check.status = HCHK_STATUS_INI;
newsrv->check.type = curproxy->options2 & PR_O2_CHK_ANY;
newsrv->check.server = newsrv;
newsrv->state |= SRV_CHECKED;
}