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

Signed-off-by: Simon Horman <ho...@verge.net.au>

---

v5
* Remove server argument from init_check. It is not used.
* Set type in init_check

  This allows a zero type to be used to indicate that
  a task for a secondary agent check should not be stated.
---
 src/cfgparse.c | 62 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/src/cfgparse.c b/src/cfgparse.c
index efbdad8..c70700d 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -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)
 {
@@ -4231,6 +4259,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;
@@ -4790,6 +4821,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);
@@ -4835,33 +4868,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;
                }
 
-- 
1.8.3.2


Reply via email to