]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: checks: make use of the post-init registration to start checks
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 19:04:48 +0000 (20:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 20:30:54 +0000 (21:30 +0100)
Instead of calling the checks directly from the init code, we now
register the start_checks() function to be run at this point. This
also allows to unexport the check init function and to remove one
include from haproxy.c.

include/proto/checks.h
src/checks.c
src/haproxy.c

index bf771ea5e35d5459f971663e44b21412dd90a230..3c6eb7ff9a676bbb8894f408b5cc152a7442604b 100644 (file)
@@ -27,7 +27,6 @@
 
 const char *get_check_status_description(short check_status);
 const char *get_check_status_info(short check_status);
-int start_checks();
 void __health_adjust(struct server *s, short status);
 int trigger_resolution(struct server *s);
 
index 8eb2c7a45face48dbe0b629522100267af7df8a6..b1e45499fd77f742f131710c6de1703109804fe2 100644 (file)
@@ -2331,9 +2331,10 @@ static int start_check_task(struct check *check, int mininter,
 
 /*
  * Start health-check.
- * Returns 0 if OK, -1 if error, and prints the error in this case.
+ * Returns 0 if OK, ERR_FATAL on error, and prints the error in this case.
  */
-int start_checks() {
+static int start_checks()
+{
 
        struct proxy *px;
        struct server *s;
@@ -2352,7 +2353,7 @@ int start_checks() {
                        if (s->slowstart) {
                                if ((t = task_new()) == NULL) {
                                        Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
-                                       return -1;
+                                       return ERR_ALERT | ERR_FATAL;
                                }
                                /* We need a warmup task that will be called when the server
                                 * state switches from down to up.
@@ -2396,7 +2397,7 @@ int start_checks() {
                if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
                        if (init_pid_list()) {
                                Alert("Starting [%s] check: out of memory.\n", px->id);
-                               return -1;
+                               return ERR_ALERT | ERR_FATAL;
                        }
                }
 
@@ -2405,17 +2406,17 @@ int start_checks() {
                        if (s->check.state & CHK_ST_CONFIGURED) {
                                if (s->check.type == PR_O2_EXT_CHK) {
                                        if (!prepare_external_check(&s->check))
-                                               return -1;
+                                               return ERR_ALERT | ERR_FATAL;
                                }
                                if (!start_check_task(&s->check, mininter, nbcheck, srvpos))
-                                       return -1;
+                                       return ERR_ALERT | ERR_FATAL;
                                srvpos++;
                        }
 
                        /* A task for a auxiliary agent check */
                        if (s->agent.state & CHK_ST_CONFIGURED) {
                                if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) {
-                                       return -1;
+                                       return ERR_ALERT | ERR_FATAL;
                                }
                                srvpos++;
                        }
@@ -3455,6 +3456,12 @@ int srv_check_healthcheck_port(struct check *chk)
        return 0;
 }
 
+__attribute__((constructor))
+static void __check_init(void)
+{
+       hap_register_post_check(start_checks);
+}
+
 
 /*
  * Local variables:
index 780ca3c1a7e3fc126420ba96af670f75e11b8e7b..5d43cf388069cf886dd3f3ebf79ac95c8d1ba18d 100644 (file)
@@ -89,7 +89,6 @@
 #include <proto/auth.h>
 #include <proto/backend.h>
 #include <proto/channel.h>
-#include <proto/checks.h>
 #include <proto/connection.h>
 #include <proto/fd.h>
 #include <proto/filters.h>
@@ -946,9 +945,6 @@ static void init(int argc, char **argv)
                }
        }
 
-       if (start_checks() < 0)
-               exit(1);
-
        list_for_each_entry(pcf, &post_check_list, list) {
                err_code |= pcf->fct();
                if (err_code & (ERR_ABORT|ERR_FATAL))