[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 5c6e982..aefee32 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -27,6 +27,7 @@
 #include <common/config.h>
 #include <types/log.h>
 #include <types/protocols.h>
+#include <types/proxy.h>
 #include <types/task.h>
 
 /* modes of operation (global.mode) */
@@ -80,7 +81,7 @@
 		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 d7c5110..0615366 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -44,6 +44,7 @@
 #include <proto/freq_ctr.h>
 #include <proto/pipe.h>
 #include <proto/proto_uxst.h>
+#include <proto/proxy.h>
 #include <proto/session.h>
 #include <proto/server.h>
 #include <proto/stream_interface.h>
@@ -78,12 +79,42 @@
 		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 @@
 			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 a592d46..09f8288 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -113,9 +113,7 @@
 	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 8c1f2c5..742d116 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -450,8 +450,7 @@
 
 		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 */