From: Willy Tarreau Date: Sun, 16 Aug 2009 15:41:45 +0000 (+0200) Subject: [MEDIUM] make the global stats socket part of a frontend X-Git-Tag: v1.4-dev3~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89a6313c34aededa867a523afd1ade20e410ca9b;p=thirdparty%2Fhaproxy.git [MEDIUM] make the global stats socket part of a frontend Creating a frontend for the global stats socket will help merge unix sockets management with the other socket management. Since frontends are huge structs, we only allocate it if required. --- diff --git a/include/types/global.h b/include/types/global.h index 5c6e982175..aefee32260 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -27,6 +27,7 @@ #include #include #include +#include #include /* modes of operation (global.mode) */ @@ -80,7 +81,7 @@ struct global { int recv_enough; /* how many input bytes at once are "enough" */ } tune; struct listener stats_sock; /* unix socket listener for statistics */ - int stats_timeout; /* in ticks */ + struct proxy *stats_fe; /* the frontend holding the stats settings */ }; extern struct global global; diff --git a/src/dumpstats.c b/src/dumpstats.c index d7c5110df7..0615366824 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -78,12 +79,42 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx su.sun_path[sizeof(su.sun_path) - 1] = 0; memcpy(&global.stats_sock.addr, &su, sizeof(su)); // guaranteed to fit + if (!global.stats_fe) { + if ((global.stats_fe = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) { + snprintf(err, errlen, "out of memory"); + return -1; + } + + LIST_INIT(&global.stats_fe->pendconns); + LIST_INIT(&global.stats_fe->acl); + LIST_INIT(&global.stats_fe->block_cond); + LIST_INIT(&global.stats_fe->redirect_rules); + LIST_INIT(&global.stats_fe->mon_fail_cond); + LIST_INIT(&global.stats_fe->switching_rules); + LIST_INIT(&global.stats_fe->tcp_req.inspect_rules); + + /* Timeouts are defined as -1, so we cannot use the zeroed area + * as a default value. + */ + proxy_reset_timeouts(global.stats_fe); + + global.stats_fe->last_change = now.tv_sec; + global.stats_fe->id = strdup("GLOBAL"); + global.stats_fe->cap = PR_CAP_FE; + } + global.stats_sock.state = LI_INIT; global.stats_sock.options = LI_O_NONE; global.stats_sock.accept = uxst_event_accept; global.stats_sock.handler = uxst_process_session; global.stats_sock.analysers = AN_REQ_UNIX_STATS; - global.stats_sock.private = NULL; + global.stats_sock.private = global.stats_fe; /* must point to the frontend */ + + global.stats_fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ + global.stats_sock.timeout = &global.stats_fe->timeout.client; + + global.stats_sock.next = global.stats_fe->listen; + global.stats_fe->listen = &global.stats_sock; cur_arg = 2; while (*args[cur_arg]) { @@ -143,7 +174,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx snprintf(err, errlen, "a positive value is expected for 'stats timeout' in 'global section'"); return -1; } - global.stats_timeout = MS_TO_TICKS(timeout); + global.stats_fe->timeout.client = MS_TO_TICKS(timeout); } else if (!strcmp(args[0], "maxconn")) { int maxconn = atol(args[1]); diff --git a/src/haproxy.c b/src/haproxy.c index a592d46f86..09f828809d 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -113,9 +113,7 @@ struct global global = { logfac2 : -1, loglev1 : 7, /* max syslog level : debug */ loglev2 : 7, - .stats_timeout = MS_TO_TICKS(10000), /* stats timeout = 10 seconds */ .stats_sock = { - .timeout = &global.stats_timeout, .maxconn = 10, /* 10 concurrent stats connections */ .perm = { .ux = { diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 8c1f2c56ac..742d1160b2 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -450,8 +450,7 @@ int uxst_event_accept(int fd) { s->task = t; s->listener = l; - s->fe = NULL; - s->be = NULL; + s->fe = s->be = l->private; s->ana_state = 0; s->req = s->rep = NULL; /* will be allocated later */