MINOR: srv: extract tracking server config function

Extract the post-config tracking setup in a dedicated function
srv_apply_track. This will be useful to implement track support for
dynamic servers.
diff --git a/include/haproxy/server.h b/include/haproxy/server.h
index b807a8a..c39b0e3 100644
--- a/include/haproxy/server.h
+++ b/include/haproxy/server.h
@@ -75,6 +75,8 @@
 struct task *srv_cleanup_idle_conns(struct task *task, void *ctx, unsigned int state);
 struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
 
+int srv_apply_track(struct server *srv, struct proxy *curproxy);
+
 /*
  * Registers the server keyword list <kwl> as a list of valid keywords for next
  * parsing sessions.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 6bf8e6d..5e21467 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -3445,72 +3445,10 @@
 				ha_warning("server has tfo activated, the backend should be configured with at least 'conn-failure', 'empty-response' and 'response-timeout' or we wouldn't be able to retry the connection on failure.\n");
 
 			if (newsrv->trackit) {
-				struct proxy *px;
-				struct server *srv, *loop;
-				char *pname, *sname;
-
-				pname = newsrv->trackit;
-				sname = strrchr(pname, '/');
-
-				if (sname)
-					*sname++ = '\0';
-				else {
-					sname = pname;
-					pname = NULL;
-				}
-
-				if (pname) {
-					px = proxy_be_by_name(pname);
-					if (!px) {
-						ha_alert("unable to find required proxy '%s' for tracking.\n",
-						         pname);
-						cfgerr++;
-						goto next_srv;
-					}
-				} else
-					px = curproxy;
-
-				srv = findserver(px, sname);
-				if (!srv) {
-					ha_alert("unable to find required server '%s' for tracking.\n",
-						 sname);
-					cfgerr++;
-					goto next_srv;
-				}
-
-				if (!srv->do_check && !srv->do_agent && !srv->track && !srv->trackit) {
-					ha_alert("unable to use %s/%s for "
-						 "tracking as it does not have any check nor agent enabled.\n",
-						 px->id, srv->id);
-					cfgerr++;
-					goto next_srv;
-				}
-
-				for (loop = srv->track; loop && loop != newsrv; loop = loop->track);
-
-				if (newsrv == srv || loop) {
-					ha_alert("unable to track %s/%s as it "
-						 "belongs to a tracking chain looping back to %s/%s.\n",
-						 px->id, srv->id, px->id,
-						 newsrv == srv ? srv->id : loop->id);
-					cfgerr++;
-					goto next_srv;
-				}
-
-				if (curproxy != px &&
-					(curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
-					ha_alert("unable to use %s/%s for"
-						 "tracking: disable-on-404 option inconsistency.\n",
-						 px->id, srv->id);
-					cfgerr++;
+				if (srv_apply_track(newsrv, curproxy)) {
+					++cfgerr;
 					goto next_srv;
 				}
-
-				newsrv->track = srv;
-				newsrv->tracknext = srv->trackers;
-				srv->trackers = newsrv;
-
-				ha_free(&newsrv->trackit);
 			}
 
 		next_srv:
diff --git a/src/server.c b/src/server.c
index 073d3be..1ad4c2e 100644
--- a/src/server.c
+++ b/src/server.c
@@ -4715,6 +4715,91 @@
 
 INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
 
+/* Prepare a server <srv> to track check status of another one. <srv>.<trackit>
+ * field is used to retrieve the identifier of the tracked server, either with
+ * the format "proxy/server" or just "server". <curproxy> must point to the
+ * backend owning <srv>; if no proxy is specified in <trackit>, it will be used
+ * to find the tracked server.
+ *
+ * Returns 0 if the server track has been activated else non-zero.
+ *
+ * Not thread-safe.
+ */
+int srv_apply_track(struct server *srv, struct proxy *curproxy)
+{
+	struct proxy *px;
+	struct server *strack, *loop;
+	char *pname, *sname;
+
+	if (!srv->trackit)
+		return 1;
+
+	pname = srv->trackit;
+	sname = strrchr(pname, '/');
+
+	if (sname) {
+		*sname++ = '\0';
+	}
+	else {
+		sname = pname;
+		pname = NULL;
+	}
+
+	if (pname) {
+		px = proxy_be_by_name(pname);
+		if (!px) {
+			ha_alert("unable to find required proxy '%s' for tracking.\n",
+			         pname);
+			return 1;
+		}
+	}
+	else {
+		px = curproxy;
+	}
+
+	strack = findserver(px, sname);
+	if (!strack) {
+		ha_alert("unable to find required server '%s' for tracking.\n",
+		         sname);
+		return 1;
+	}
+
+	if (!strack->do_check && !strack->do_agent && !strack->track &&
+	    !strack->trackit) {
+		ha_alert("unable to use %s/%s for "
+		         "tracking as it does not have any check nor agent enabled.\n",
+		         px->id, strack->id);
+		return 1;
+	}
+
+	for (loop = strack->track; loop && loop != srv; loop = loop->track)
+		;
+
+	if (srv == strack || loop) {
+		ha_alert("unable to track %s/%s as it "
+		         "belongs to a tracking chain looping back to %s/%s.\n",
+		         px->id, strack->id, px->id,
+		         srv == strack ? strack->id : loop->id);
+		return 1;
+	}
+
+	if (curproxy != px &&
+	    (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
+		ha_alert("unable to use %s/%s for"
+		         "tracking: disable-on-404 option inconsistency.\n",
+		         px->id, strack->id);
+		return 1;
+	}
+
+	srv->track = strack;
+	srv->tracknext = strack->trackers;
+	strack->trackers = srv;
+
+	ha_free(&srv->trackit);
+
+	return 0;
+}
+
 /*
  * This function applies server's status changes, it is
  * is designed to be called asynchronously.