mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-12 14:35:14 +00:00
MINOR: haproxy: add a registration for build options
Many extensions now report some build options to ease debugging, but this is now being done at the expense of code maintainability. Let's provide a registration function to do this so that we can start to remove most of the #ifdefs from haproxy.c (18 currently just for a single function).
This commit is contained in:
parent
1b5af7cd42
commit
cdb737e5a2
@ -264,6 +264,8 @@ static inline int already_warned(unsigned int warning)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hap_register_build_opts(const char *str, int must_free);
|
||||
|
||||
#endif /* _TYPES_GLOBAL_H */
|
||||
|
||||
/*
|
||||
|
@ -267,10 +267,40 @@ static struct task *manage_global_listener_queue(struct task *t);
|
||||
/* bitfield of a few warnings to emit just once (WARN_*) */
|
||||
unsigned int warned = 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;
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
/* 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_ADDQ(&build_opts_list, &b->list);
|
||||
}
|
||||
|
||||
static void display_version()
|
||||
{
|
||||
printf("HA-Proxy version " HAPROXY_VERSION " " HAPROXY_DATE"\n");
|
||||
@ -279,6 +309,8 @@ static void display_version()
|
||||
|
||||
static void display_build_opts()
|
||||
{
|
||||
struct build_opts_str *item;
|
||||
|
||||
printf("Build options :"
|
||||
#ifdef BUILD_TARGET
|
||||
"\n TARGET = " BUILD_TARGET
|
||||
@ -435,6 +467,10 @@ static void display_build_opts()
|
||||
#ifdef USE_WURFL
|
||||
printf("Built with WURFL support\n");
|
||||
#endif
|
||||
list_for_each_entry(item, &build_opts_list, list) {
|
||||
puts(item->str);
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
|
||||
list_pollers(stdout);
|
||||
@ -1376,6 +1412,7 @@ static void deinit(void)
|
||||
struct logsrv *log, *logb;
|
||||
struct logformat_node *lf, *lfb;
|
||||
struct bind_conf *bind_conf, *bind_back;
|
||||
struct build_opts_str *bol, *bolb;
|
||||
int i;
|
||||
|
||||
deinit_signals();
|
||||
@ -1680,6 +1717,13 @@ static void deinit(void)
|
||||
free(wl);
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(bol, bolb, &build_opts_list, list) {
|
||||
if (bol->must_free)
|
||||
free((void *)bol->str);
|
||||
LIST_DEL(&bol->list);
|
||||
free(bol);
|
||||
}
|
||||
|
||||
vars_prune(&global.vars, NULL, NULL);
|
||||
|
||||
pool_destroy2(pool2_stream);
|
||||
|
Loading…
Reference in New Issue
Block a user