]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: Refactor init_check and move to checks.c
authorSimon Horman <horms@verge.net.au>
Fri, 30 Jan 2015 02:22:54 +0000 (11:22 +0900)
committerWilly Tarreau <w@1wt.eu>
Mon, 2 Feb 2015 23:24:15 +0000 (00:24 +0100)
Refactor init_check so that an error string is returned
rather than alerts being printed by it. Also
init_check to checks.c and provide a prototype to allow
it to be used from multiple C files.

Signed-off-by: Simon Horman <horms@verge.net.au>
include/proto/checks.h
src/checks.c
src/server.c

index f3d4fa6edd4e4b4277fe63fcd22772f19de5dcff..1e65652eb7f6ca9cc42f681ea0b08a5a4bfdc078 100644 (file)
@@ -44,6 +44,8 @@ static inline void health_adjust(struct server *s, short status)
        return __health_adjust(s, status);
 }
 
+const char *init_check(struct check *check, int type);
+
 #endif /* _PROTO_CHECKS_H */
 
 /*
index 321fe3415e263d2b28368eb1ffc1fe8263806b9a..ae981f8fb97e0c9185b1cafec3a43c7e830019e9 100644 (file)
@@ -2781,6 +2781,32 @@ static void tcpcheck_main(struct connection *conn)
        return;
 }
 
+const char *init_check(struct check *check, int type)
+{
+       check->type = type;
+
+       /* Allocate buffer for requests... */
+       if ((check->bi = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
+               return "out of memory while allocating check buffer";
+       }
+       check->bi->size = global.tune.chksize;
+
+       /* Allocate buffer for responses... */
+       if ((check->bo = calloc(sizeof(struct buffer) + global.tune.chksize, sizeof(char))) == NULL) {
+               return "out of memory while allocating check buffer";
+       }
+       check->bo->size = global.tune.chksize;
+
+       /* Allocate buffer for partial results... */
+       if ((check->conn = calloc(1, sizeof(struct connection))) == NULL) {
+               return "out of memory while allocating check connection";
+       }
+
+       check->conn->t.sock.fd = -1; /* no agent in progress yet */
+
+       return NULL;
+}
+
 
 /*
  * Local variables:
index b19ebbeca950944564bf80f40948d12190a8b525..8554e759d3c5c204e4c3cf8a86f12c1d116debcf 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <types/global.h>
 
+#include <proto/checks.h>
 #include <proto/port_range.h>
 #include <proto/protocol.h>
 #include <proto/queue.h>
@@ -796,35 +797,6 @@ const char *server_parse_weight_change_request(struct server *sv,
        return NULL;
 }
 
-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 parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, struct proxy *defproxy)
 {
        struct server *newsrv = NULL;
@@ -1592,7 +1564,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                }
 
                if (do_check) {
-                       int ret;
+                       const char *ret;
 
                        if (newsrv->trackit) {
                                Alert("parsing [%s:%d]: unable to enable checks and tracking at the same time!\n",
@@ -1671,9 +1643,10 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        }
 
                        /* note: check type will be set during the config review phase */
-                       ret = init_check(&newsrv->check, 0, file, linenum);
+                       ret = init_check(&newsrv->check, 0);
                        if (ret) {
-                               err_code |= ret;
+                               Alert("parsing [%s:%d] : %s.\n", file, linenum, ret);
+                               err_code |= ERR_ALERT | ERR_ABORT;
                                goto out;
                        }
 
@@ -1681,7 +1654,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                }
 
                if (do_agent) {
-                       int ret;
+                       const char *ret;
 
                        if (!newsrv->agent.port) {
                                Alert("parsing [%s:%d] : server %s does not have agent port. Agent check has been disabled.\n",
@@ -1693,9 +1666,10 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        if (!newsrv->agent.inter)
                                newsrv->agent.inter = newsrv->check.inter;
 
-                       ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK, file, linenum);
+                       ret = init_check(&newsrv->agent, PR_O2_LB_AGENT_CHK);
                        if (ret) {
-                               err_code |= ret;
+                               Alert("parsing [%s:%d] : %s.\n", file, linenum, ret);
+                               err_code |= ERR_ALERT | ERR_ABORT;
                                goto out;
                        }