+#include <stdlib.h>
+#include <string.h>
+
#include <haproxy/global.h>
#include <haproxy/list.h>
#include <haproxy/protocol-t.h>
#include <haproxy/ticks.h>
+#include <haproxy/tools.h>
+#include <haproxy/version.h>
/* global options */
struct global global = {
};
int stopping; /* non zero means stopping in progress */
+
+/* These are strings to be reported in the output of "haproxy -vv". They may
+ * either be constants (in which case must_free must be zero) or dynamically
+ * allocated strings to pass to free() on exit, and in this case must_free
+ * must be non-zero.
+ */
+struct list build_opts_list = LIST_HEAD_INIT(build_opts_list);
+struct build_opts_str {
+ struct list list;
+ const char *str;
+ int must_free;
+};
+
+/*********************************************************************/
+/* general purpose functions ***************************************/
+/*********************************************************************/
+
+/* used to register some build option strings at boot. Set must_free to
+ * non-zero if the string must be freed upon exit.
+ */
+void hap_register_build_opts(const char *str, int must_free)
+{
+ struct build_opts_str *b;
+
+ b = calloc(1, sizeof(*b));
+ if (!b) {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+ b->str = str;
+ b->must_free = must_free;
+ LIST_APPEND(&build_opts_list, &b->list);
+}
+
+/* returns the first build option when <curr> is NULL, or the next one when
+ * <curr> is passed the last returned value. NULL when there is no more entries
+ * in the list. Otherwise the returned pointer is &opt->str so the caller can
+ * print it as *ret.
+ */
+const char **hap_get_next_build_opt(const char **curr)
+{
+ struct build_opts_str *head, *start;
+
+ head = container_of(&build_opts_list, struct build_opts_str, list);
+
+ if (curr)
+ start = container_of(curr, struct build_opts_str, str);
+ else
+ start = head;
+
+ start = container_of(start->list.n, struct build_opts_str, list);
+
+ if (start == head)
+ return NULL;
+
+ return &start->str;
+}
+
+/* used to make a new feature appear in the build_features list at boot time.
+ * The feature must be in the format "XXX" without the leading "+" which will
+ * be automatically appended.
+ */
+void hap_register_feature(const char *name)
+{
+ static int must_free = 0;
+ int new_len = strlen(build_features) + 2 + strlen(name);
+ char *new_features;
+ char *startp, *endp;
+ int found = 0;
+
+ new_features = malloc(new_len + 1);
+ if (!new_features)
+ return;
+
+ strlcpy2(new_features, build_features, new_len);
+
+ startp = new_features;
+
+ /* look if the string already exists */
+ while (startp) {
+ char *sign = startp;
+
+ /* tokenize for simpler strcmp */
+ endp = strchr(startp, ' ');
+ if (endp)
+ *endp = '\0';
+
+ startp++; /* skip sign */
+
+ if (strcmp(startp, name) == 0) {
+ *sign = '+';
+ found = 1;
+ }
+
+ /* couldn't find a space, that's the end of the string */
+ if (!endp)
+ break;
+
+ *endp = ' ';
+ startp = endp + 1;
+
+ if (found)
+ break;
+ }
+
+ /* if we didn't find the feature add it to the string */
+ if (!found)
+ snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
+
+ if (must_free)
+ ha_free(&build_features);
+
+ build_features = new_features;
+ must_free = 1;
+}
+
+void ha_free_build_opts_list(void)
+{
+ struct build_opts_str *bol, *bolb;
+
+ list_for_each_entry_safe(bol, bolb, &build_opts_list, list) {
+ if (bol->must_free)
+ free((void *)bol->str);
+ LIST_DELETE(&bol->list);
+ free(bol);
+ }
+}
return 0;
}
-/* These are strings to be reported in the output of "haproxy -vv". They may
- * either be constants (in which case must_free must be zero) or dynamically
- * allocated strings to pass to free() on exit, and in this case must_free
- * must be non-zero.
- */
-struct list build_opts_list = LIST_HEAD_INIT(build_opts_list);
-struct build_opts_str {
- struct list list;
- const char *str;
- int must_free;
-};
-
int mode_stress_level = 0;
-/*********************************************************************/
-/* general purpose functions ***************************************/
-/*********************************************************************/
-
-/* used to register some build option strings at boot. Set must_free to
- * non-zero if the string must be freed upon exit.
- */
-void hap_register_build_opts(const char *str, int must_free)
-{
- struct build_opts_str *b;
-
- b = calloc(1, sizeof(*b));
- if (!b) {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
- b->str = str;
- b->must_free = must_free;
- LIST_APPEND(&build_opts_list, &b->list);
-}
-
-/* returns the first build option when <curr> is NULL, or the next one when
- * <curr> is passed the last returned value. NULL when there is no more entries
- * in the list. Otherwise the returned pointer is &opt->str so the caller can
- * print it as *ret.
- */
-const char **hap_get_next_build_opt(const char **curr)
-{
- struct build_opts_str *head, *start;
-
- head = container_of(&build_opts_list, struct build_opts_str, list);
-
- if (curr)
- start = container_of(curr, struct build_opts_str, str);
- else
- start = head;
-
- start = container_of(start->list.n, struct build_opts_str, list);
-
- if (start == head)
- return NULL;
-
- return &start->str;
-}
-
-/* used to make a new feature appear in the build_features list at boot time.
- * The feature must be in the format "XXX" without the leading "+" which will
- * be automatically appended.
- */
-void hap_register_feature(const char *name)
-{
- static int must_free = 0;
- int new_len = strlen(build_features) + 2 + strlen(name);
- char *new_features;
- char *startp, *endp;
- int found = 0;
-
- new_features = malloc(new_len + 1);
- if (!new_features)
- return;
-
- strlcpy2(new_features, build_features, new_len);
-
- startp = new_features;
-
- /* look if the string already exists */
- while (startp) {
- char *sign = startp;
-
- /* tokenize for simpler strcmp */
- endp = strchr(startp, ' ');
- if (endp)
- *endp = '\0';
-
- startp++; /* skip sign */
-
- if (strcmp(startp, name) == 0) {
- *sign = '+';
- found = 1;
- }
-
- /* couldn't find a space, that's the end of the string */
- if (!endp)
- break;
-
- *endp = ' ';
- startp = endp + 1;
-
- if (found)
- break;
- }
-
- /* if we didn't find the feature add it to the string */
- if (!found)
- snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
-
- if (must_free)
- ha_free(&build_features);
-
- build_features = new_features;
- must_free = 1;
-}
-
#ifdef DEBUG_UNIT
/* register a function that could be registered in "-U" argument */
void hap_register_unittest(const char *name, int (*fct)(int argc, char **argv))
struct proxy *p = proxies_list, *p0;
struct cfgfile *cfg, *cfg_tmp;
struct logger *log, *logb;
- struct build_opts_str *bol, *bolb;
struct post_deinit_fct *pdf, *pdfb;
struct proxy_deinit_fct *pxdf, *pxdfb;
struct server_deinit_fct *srvdf, *srvdfb;
ha_free(&cfg);
}
- list_for_each_entry_safe(bol, bolb, &build_opts_list, list) {
- if (bol->must_free)
- free((void *)bol->str);
- LIST_DELETE(&bol->list);
- free(bol);
- }
+ ha_free_build_opts_list();
list_for_each_entry_safe(pxdf, pxdfb, &proxy_deinit_list, list) {
LIST_DELETE(&pxdf->list);