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>
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 3bc700b..b16c310 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -1620,6 +1620,34 @@
 	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 @@
 
 			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 @@
 		}
 
 		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);
@@ -4876,34 +4909,15 @@
 				err_code |= ERR_ALERT | ERR_FATAL;
 				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;
 		}