MINOR/CLEANUP: proxy: rename "proxy" to "proxies_list"

Rename the global variable "proxy" to "proxies_list".
There's been multiple proxies in haproxy for quite some time, and "proxy"
is a potential source of bugs, a number of functions have a "proxy" argument,
and some code used "proxy" when it really meant "px" or "curproxy". It worked
by pure luck, because it usually happened while parsing the config, and thus
"proxy" pointed to the currently parsed proxy, but we should probably not
rely on this.

[wt: some of these are definitely fixes that are worth backporting]
diff --git a/src/cache.c b/src/cache.c
index 97861d7..ae345a1 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -840,7 +840,7 @@
 	int err = 0;
 	struct flt_conf *fconf;
 
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 
 		/* resolve the http response cache name to a ptr in the action rule */
 		list_for_each_entry(hresrule, &curproxy->http_res_rules, list) {
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 685fbe9..f66f416 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -2747,8 +2747,8 @@
 		}
 
 		init_new_proxy(curproxy);
-		curproxy->next = proxy;
-		proxy = curproxy;
+		curproxy->next = proxies_list;
+		proxies_list = curproxy;
 		curproxy->conf.args.file = curproxy->conf.file = strdup(file);
 		curproxy->conf.args.line = curproxy->conf.line = linenum;
 		curproxy->last_change = now.tv_sec;
@@ -7546,18 +7546,18 @@
 
 	/* first, we will invert the proxy list order */
 	curproxy = NULL;
-	while (proxy) {
+	while (proxies_list) {
 		struct proxy *next;
 
-		next = proxy->next;
-		proxy->next = curproxy;
-		curproxy = proxy;
+		next = proxies_list->next;
+		proxies_list->next = curproxy;
+		curproxy = proxies_list;
 		if (!next)
 			break;
-		proxy = next;
+		proxies_list = next;
 	}
 
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		struct switching_rule *rule;
 		struct server_rule *srule;
 		struct sticking_rule *mrule;
@@ -8819,7 +8819,7 @@
 	}
 
 	/* Make each frontend inherit bind-process from its listeners when not specified. */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		if (curproxy->bind_proc)
 			continue;
 
@@ -8849,14 +8849,14 @@
 	 * are any fatal errors as we must not call it with unresolved proxies.
 	 */
 	if (!cfgerr) {
-		for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+		for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 			if (curproxy->cap & PR_CAP_FE)
 				propagate_processes(curproxy, NULL);
 		}
 	}
 
 	/* Bind each unbound backend to all processes when not specified. */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		if (curproxy->bind_proc)
 			continue;
 		curproxy->bind_proc = nbits(global.nbproc);
@@ -8868,7 +8868,7 @@
 
 	/* perform the final checks before creating tasks */
 
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		struct listener *listener;
 		unsigned int next_id;
 
@@ -9000,7 +9000,7 @@
 	/* automatically compute fullconn if not set. We must not do it in the
 	 * loop above because cross-references are not yet fully resolved.
 	 */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		/* If <fullconn> is not set, let's set it to 10% of the sum of
 		 * the possible incoming frontend's maxconns.
 		 */
@@ -9019,7 +9019,7 @@
 	 * Recount currently required checks.
 	 */
 
-	for (curproxy=proxy; curproxy; curproxy=curproxy->next) {
+	for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) {
 		int optnum;
 
 		for (optnum = 0; cfg_opts[optnum].name; optnum++)
@@ -9032,7 +9032,7 @@
 	}
 
 	/* compute the required process bindings for the peers */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next)
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next)
 		if (curproxy->table.peers.p)
 			curproxy->table.peers.p->peers_fe->bind_proc |= curproxy->bind_proc;
 
@@ -9099,7 +9099,7 @@
 	 * be done earlier because the data size may be discovered while parsing
 	 * other proxies.
 	 */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		if (curproxy->state == PR_STSTOPPED)
 			continue;
 
@@ -9147,7 +9147,7 @@
 
 	/* Update server_state_file_name to backend name if backend is supposed to use
 	 * a server-state file locally defined and none has been provided */
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 		if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL &&
 		    curproxy->server_state_file_name == NULL)
 			curproxy->server_state_file_name = strdup(curproxy->id);
diff --git a/src/checks.c b/src/checks.c
index dc970e0..4aef54e 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -2332,7 +2332,7 @@
 	 * a shorter interval will start independently and will not dictate
 	 * too short an interval for all others.
 	 */
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		for (s = px->srv; s; s = s->next) {
 			if (s->slowstart) {
 				if ((t = task_new(MAX_THREADS_MASK)) == NULL) {
@@ -2376,7 +2376,7 @@
 	 * start them after their interval set to the min interval divided by
 	 * the number of servers, weighted by the server's position in the list.
 	 */
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
 			if (init_pid_list()) {
 				ha_alert("Starting [%s] check: out of memory.\n", px->id);
diff --git a/src/cli.c b/src/cli.c
index 3d88780..149ecd7 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -170,8 +170,8 @@
 		return NULL;
 
 	init_new_proxy(fe);
-	fe->next = proxy;
-	proxy = fe;
+	fe->next = proxies_list;
+	proxies_list = fe;
 	fe->last_change = now.tv_sec;
 	fe->id = strdup("GLOBAL");
 	fe->cap = PR_CAP_FE;
@@ -1276,7 +1276,7 @@
 	 * First, calculates the total number of FD, so that we can let
 	 * the caller know how much he should expects.
 	 */
-	px = proxy;
+	px = proxies_list;
 	while (px) {
 		struct listener *l;
 
@@ -1313,7 +1313,7 @@
 	cmsg->cmsg_type = SCM_RIGHTS;
 	tmpfd = (int *)CMSG_DATA(cmsg);
 
-	px = proxy;
+	px = proxies_list;
 	/* For each socket, e message is sent, containing the following :
 	 *  Size of the namespace name (or 0 if none), as an unsigned char.
 	 *  The namespace name, if any
diff --git a/src/dns.c b/src/dns.c
index a83c8aa..8db8290 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -1897,7 +1897,7 @@
 		task_wakeup(t, TASK_WOKEN_INIT);
 	}
 
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		struct server *srv;
 
 		for (srv = px->srv; srv; srv = srv->next) {
diff --git a/src/filters.c b/src/filters.c
index bf188b5..e9982ca 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -288,7 +288,7 @@
 	struct proxy *px;
 	int err_code = 0;
 
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		err_code |= flt_init(px);
 		if (err_code & (ERR_ABORT|ERR_FATAL)) {
 			ha_alert("Failed to initialize filters for proxy '%s'.\n",
@@ -307,7 +307,7 @@
 	struct proxy *px;
 	int err_code = 0;
 
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		err_code = flt_init_per_thread(px);
 		if (err_code & (ERR_ABORT|ERR_FATAL)) {
 			ha_alert("Failed to initialize filters for proxy '%s' for thread %u.\n",
@@ -376,7 +376,7 @@
 {
 	struct proxy *px;
 
-	for (px = proxy; px; px = px->next)
+	for (px = proxies_list; px; px = px->next)
 		flt_deinit_per_thread(px);
 }
 
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 717715a..b653109 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -2796,7 +2796,7 @@
 {
 	struct proxy *p;
 
-	p = proxy;
+	p = proxies_list;
 	while (p) {
 		struct flt_conf *fconf;
 
diff --git a/src/haproxy.c b/src/haproxy.c
index 18d2cbf..219a8ea 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -555,7 +555,7 @@
 	struct listener *l, *l_next;
 	struct proxy *curproxy;
 
-	for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) {
 
 		list_for_each_entry_safe(l, l_next, &curproxy->conf.listeners, by_fe) {
 			/* does not close if the FD is inherited with fd@
@@ -821,7 +821,7 @@
  */
 static void sig_dump_state(struct sig_handler *sh)
 {
-	struct proxy *p = proxy;
+	struct proxy *p = proxies_list;
 
 	ha_warning("SIGHUP received, dumping servers states.\n");
 	while (p) {
@@ -1540,7 +1540,7 @@
 	/* Apply server states */
 	apply_server_state();
 
-	for (px = proxy; px; px = px->next)
+	for (px = proxies_list; px; px = px->next)
 		srv_compute_all_admin_states(px);
 
 	/* Apply servers' configured address */
@@ -1558,7 +1558,7 @@
 			if (pr->peers_fe)
 				break;
 
-		for (px = proxy; px; px = px->next)
+		for (px = proxies_list; px; px = px->next)
 			if (px->state == PR_STNEW && !LIST_ISEMPTY(&px->conf.listeners))
 				break;
 
@@ -1745,7 +1745,7 @@
 		struct proxy *cur;
 		int nbfe = 0, nbbe = 0;
 
-		for (cur = proxy; cur; cur = cur->next) {
+		for (cur = proxies_list; cur; cur = cur->next) {
 			if (cur->options2 & (PR_O2_SPLIC_ANY)) {
 				if (cur->cap & PR_CAP_FE)
 					nbfe += cur->maxconn;
@@ -1926,7 +1926,7 @@
 
 void deinit(void)
 {
-	struct proxy *p = proxy, *p0;
+	struct proxy *p = proxies_list, *p0;
 	struct cap_hdr *h,*h_next;
 	struct server *s,*s_next;
 	struct listener *l,*l_next;
@@ -2823,7 +2823,7 @@
 		}
 
 		/* we might have to unbind some proxies from some processes */
-		px = proxy;
+		px = proxies_list;
 		while (px != NULL) {
 			if (px->bind_proc && px->state != PR_STSTOPPED) {
 				if (!(px->bind_proc & (1UL << proc))) {
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 54fbfa7..a8d53d4 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -943,7 +943,7 @@
 	lua_newtable(L);
 
 	/* List all proxies. */
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		lua_pushstring(L, px->id);
 		hlua_fcn_new_proxy(L, px);
 		lua_settable(L, -3);
@@ -957,7 +957,7 @@
 	lua_newtable(L);
 
 	/* List all proxies. */
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		if (!(px->cap & PR_CAP_FE))
 			continue;
 		lua_pushstring(L, px->id);
@@ -973,7 +973,7 @@
 	lua_newtable(L);
 
 	/* List all proxies. */
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		if (!(px->cap & PR_CAP_BE))
 			continue;
 		lua_pushstring(L, px->id);
diff --git a/src/proto_http.c b/src/proto_http.c
index 21e30cc..88a2de9 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -9184,7 +9184,7 @@
 		}
 		else if (strcmp(args[cur_arg], "if") == 0 ||
 			 strcmp(args[cur_arg], "unless") == 0) {
-			cond = build_acl_cond(file, linenum, &proxy->acl, curproxy, (const char **)args + cur_arg, errmsg);
+			cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + cur_arg, errmsg);
 			if (!cond) {
 				memprintf(errmsg, "error in condition: %s", *errmsg);
 				return NULL;
@@ -11873,9 +11873,9 @@
 	}
 
 	LIST_INIT(&rule->arg.http.logfmt);
-	proxy->conf.args.ctx = ARGC_HRQ;
-	if (!parse_logformat_string(args[cur_arg], proxy, &rule->arg.http.logfmt, LOG_OPT_HTTP,
-	                            (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
+	px->conf.args.ctx = ARGC_HRQ;
+	if (!parse_logformat_string(args[cur_arg], px, &rule->arg.http.logfmt, LOG_OPT_HTTP,
+	                            (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, err)) {
 		return ACT_RET_PRS_ERR;
 	}
 
@@ -12102,7 +12102,7 @@
 			return ACT_RET_PRS_ERR;
 		}
 
-		proxy->conf.args.ctx = ARGC_CAP;
+		px->conf.args.ctx = ARGC_CAP;
 
 		if (!args[cur_arg]) {
 			memprintf(err, "missing length value");
@@ -12162,7 +12162,7 @@
 		}
 		cur_arg++;
 
-		proxy->conf.args.ctx = ARGC_CAP;
+		px->conf.args.ctx = ARGC_CAP;
 
 		rule->action       = ACT_CUSTOM;
 		rule->action_ptr   = http_action_req_capture_by_id;
@@ -12302,7 +12302,7 @@
 	}
 	cur_arg++;
 
-	proxy->conf.args.ctx = ARGC_CAP;
+	px->conf.args.ctx = ARGC_CAP;
 
 	rule->action       = ACT_CUSTOM;
 	rule->action_ptr   = http_action_res_capture_by_id;
@@ -12399,7 +12399,7 @@
 			return 0;
 		}
 
-		appctx->ctx.errors.px = proxy;
+		appctx->ctx.errors.px = proxies_list;
 		appctx->ctx.errors.bol = 0;
 		appctx->ctx.errors.ptr = -1;
 	}
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 1f9c3f1..857ebe1 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -1398,9 +1398,9 @@
 		return ACT_RET_PRS_ERR;
 
 	where = 0;
-	if (proxy->cap & PR_CAP_FE)
+	if (px->cap & PR_CAP_FE)
 		where |= SMP_VAL_FE_HRQ_HDR;
-	if (proxy->cap & PR_CAP_BE)
+	if (px->cap & PR_CAP_BE)
 		where |= SMP_VAL_BE_HRQ_HDR;
 
 	if (!(expr->fetch->val & where)) {
diff --git a/src/proxy.c b/src/proxy.c
index 1730ba4..8500bcc 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -54,7 +54,7 @@
 
 
 int listeners;	/* # of proxy listeners, set by cfgparse */
-struct proxy *proxy  = NULL;	/* list of all existing proxies */
+struct proxy *proxies_list  = NULL;	/* list of all existing proxies */
 struct eb_root used_proxy_id = EB_ROOT;	/* list of proxy IDs in use */
 struct eb_root proxy_by_name = EB_ROOT; /* tree of proxies sorted by name */
 unsigned int error_snapshot_id = 0;     /* global ID assigned to each error then incremented */
@@ -783,7 +783,7 @@
 	int pxerr;
 	char msg[100];
 
-	for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy != NULL; curproxy = curproxy->next) {
 		if (curproxy->state != PR_STNEW)
 			continue; /* already initialized */
 
@@ -949,7 +949,7 @@
 
 	ha_warning("soft-stop running for too long, performing a hard-stop.\n");
 	send_log(NULL, LOG_WARNING, "soft-stop running for too long, performing a hard-stop.\n");
-	p = proxy;
+	p = proxies_list;
 	while (p) {
 		if ((p->cap & PR_CAP_FE) && (p->feconn > 0)) {
 			ha_warning("Proxy %s hard-stopped (%d remaining conns will be closed).\n",
@@ -990,7 +990,7 @@
 			ha_alert("out of memory trying to allocate the hard-stop task.\n");
 		}
 	}
-	p = proxy;
+	p = proxies_list;
 	tv_update_date(0,1); /* else, the old time before select will be used */
 	while (p) {
 		/* Zombie proxy, let's close the file descriptors */
@@ -1186,7 +1186,7 @@
 	struct peers *prs;
 
 	err = 0;
-	p = proxy;
+	p = proxies_list;
 	tv_update_date(0,1); /* else, the old time before select will be used */
 	while (p) {
 		err |= !pause_proxy(p);
@@ -1220,7 +1220,7 @@
 	struct peers *prs;
 
 	err = 0;
-	p = proxy;
+	p = proxies_list;
 	tv_update_date(0,1); /* else, the old time before select will be used */
 	while (p) {
 		err |= !resume_proxy(p);
@@ -1482,14 +1482,13 @@
 static int cli_io_handler_servers_state(struct appctx *appctx)
 {
 	struct stream_interface *si = appctx->owner;
-	extern struct proxy *proxy;
 	struct proxy *curproxy;
 
 	chunk_reset(&trash);
 
 	if (appctx->st2 == STAT_ST_INIT) {
 		if (!appctx->ctx.cli.p0)
-			appctx->ctx.cli.p0 = proxy;
+			appctx->ctx.cli.p0 = proxies_list;
 		appctx->st2 = STAT_ST_HEAD;
 	}
 
@@ -1523,7 +1522,6 @@
  */
 static int cli_io_handler_show_backend(struct appctx *appctx)
 {
-	extern struct proxy *proxy;
 	struct stream_interface *si = appctx->owner;
 	struct proxy *curproxy;
 
@@ -1535,7 +1533,7 @@
 			si_applet_cant_put(si);
 			return 0;
 		}
-		appctx->ctx.cli.p0 = proxy;
+		appctx->ctx.cli.p0 = proxies_list;
 	}
 
 	for (; appctx->ctx.cli.p0 != NULL; appctx->ctx.cli.p0 = curproxy->next) {
diff --git a/src/server.c b/src/server.c
index 62fc59e..9b4d66f 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2953,7 +2953,6 @@
 	char globalfilepath[MAXPATHLEN + 1];
 	char localfilepath[MAXPATHLEN + 1];
 	int len, fileopenerr, globalfilepathlen, localfilepathlen;
-	extern struct proxy *proxy;
 	struct proxy *curproxy, *bk;
 	struct server *srv;
 
@@ -3006,7 +3005,7 @@
 		globalfilepath[0] = '\0';
 
 	/* read servers state from local file */
-	for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
+	for (curproxy = proxies_list; curproxy != NULL; curproxy = curproxy->next) {
 		/* servers are only in backends */
 		if (!(curproxy->cap & PR_CAP_BE))
 			continue;
@@ -3932,7 +3931,7 @@
 	struct proxy *curproxy;
 	int return_code = 0;
 
-	curproxy = proxy;
+	curproxy = proxies_list;
 	while (curproxy) {
 		struct server *srv;
 
diff --git a/src/stats.c b/src/stats.c
index 6cef1bf..0125928 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -2550,7 +2550,7 @@
 			}
 		}
 
-		appctx->ctx.stats.px = proxy;
+		appctx->ctx.stats.px = proxies_list;
 		appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
 		appctx->st2 = STAT_ST_LIST;
 		/* fall through */
@@ -3537,7 +3537,7 @@
 	    (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
 		return 1;
 
-	for (px = proxy; px; px = px->next) {
+	for (px = proxies_list; px; px = px->next) {
 		if (clrall) {
 			memset(&px->be_counters, 0, sizeof(px->be_counters));
 			memset(&px->fe_counters, 0, sizeof(px->fe_counters));
diff --git a/src/stick_table.c b/src/stick_table.c
index 6351143..bd0c828 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -3134,7 +3134,7 @@
 		case STAT_ST_INIT:
 			appctx->ctx.table.proxy = appctx->ctx.table.target;
 			if (!appctx->ctx.table.proxy)
-				appctx->ctx.table.proxy = proxy;
+				appctx->ctx.table.proxy = proxies_list;
 
 			appctx->ctx.table.entry = NULL;
 			appctx->st2 = STAT_ST_INFO;