]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cfgparse: Factor out check initialisation
authorSimon Horman <horms@verge.net.au>
Sat, 23 Feb 2013 06:14:19 +0000 (15:14 +0900)
committerWilly Tarreau <w@1wt.eu>
Tue, 19 Nov 2013 08:36:01 +0000 (09:36 +0100)
This is in preparation for struct server having two elements
of type struct check.

Signed-off-by: Simon Horman <horms@verge.net.au>
src/cfgparse.c

index 3bc700be0c97c39f8cd9ca4280a3f49521a94129..b16c310b6e1146ead5c919edb40ad993ddf20609 100644 (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;
                }