]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: da: make use of the late init registration code
authorWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 19:39:16 +0000 (20:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Dec 2016 20:30:54 +0000 (21:30 +0100)
Instead of having a #ifdef in the main init code we now use the registered
init functions. Doing so also enables error checking as errors were previously
reported as alerts but ignored. Also they were incorrect as the 'status'
variable was hidden by a second one and was always reporting DA_SYS (which
is apparently an error) in every case including the case where no file was
loaded. The init_deviceatlas() function was unexported since it's not used
outside of this place anymore.

include/import/da.h
src/da.c
src/haproxy.c

index d129be9d2a71af30220a6adfe711b5bfee9a3fd4..90e1f7d0db22cb900ea60ef1da101f4deb4161ac 100644 (file)
@@ -5,7 +5,6 @@
 #include <types/global.h>
 #include <dac.h>
 
-int init_deviceatlas(void);
 void deinit_deviceatlas(void);
 #endif
 #endif
index 1dd148fdd68107d2a6bb55940f49cb3eabc4a41c..843da9fa7c8a3b579e0c37c8e14a708f90857b83 100644 (file)
--- a/src/da.c
+++ b/src/da.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 
 #include <common/cfgparse.h>
+#include <common/errors.h>
 #include <proto/arg.h>
 #include <proto/log.h>
 #include <proto/proto_http.h>
@@ -87,9 +88,13 @@ static void da_haproxy_log(da_severity_t severity, da_status_t status,
 
 #define        DA_COOKIENAME_DEFAULT           "DAPROPS"
 
-int init_deviceatlas(void)
+/*
+ * module init / deinit functions. Returns 0 if OK, or a combination of ERR_*.
+ */
+static int init_deviceatlas(void)
 {
-       da_status_t status = DA_SYS;
+       int err_code = 0;
+
        if (global.deviceatlas.jsonpath != 0) {
                FILE *jsonp;
                da_property_decl_t extraprops[] = {{0, 0}};
@@ -100,6 +105,7 @@ int init_deviceatlas(void)
                if (jsonp == 0) {
                        Alert("deviceatlas : '%s' json file has invalid path or is not readable.\n",
                                global.deviceatlas.jsonpath);
+                       err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
 
@@ -111,6 +117,7 @@ int init_deviceatlas(void)
                if (status != DA_OK) {
                        Alert("deviceatlas : '%s' json file is invalid.\n",
                                global.deviceatlas.jsonpath);
+                       err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
 
@@ -119,6 +126,7 @@ int init_deviceatlas(void)
 
                if (status != DA_OK) {
                        Alert("deviceatlas : data could not be compiled.\n");
+                       err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
 
@@ -135,7 +143,7 @@ int init_deviceatlas(void)
        }
 
 out:
-       return status == DA_OK;
+       return err_code;
 }
 
 void deinit_deviceatlas(void)
@@ -365,4 +373,5 @@ static void __da_init(void)
        sample_register_convs(&conv_kws);
        cfg_register_keywords(&dacfg_kws);
        hap_register_build_opts("Built with DeviceAtlas support.", 0);
+       hap_register_post_check(init_deviceatlas);
 }
index d5089da270352531a55b9553eb921816ab2a62f5..ef1b071d9bc55d1f2e686d032d25098279099be3 100644 (file)
@@ -926,9 +926,6 @@ static void init(int argc, char **argv)
 
        /* now we know the buffer size, we can initialize the channels and buffers */
        init_buffer();
-#if defined(USE_DEVICEATLAS)
-       init_deviceatlas();
-#endif
 
        list_for_each_entry(pcf, &post_check_list, list) {
                err_code |= pcf->fct();