BUG/MINOR: server: Fix server-state-file-name directive
Since the beginning, this directive is documented to accept an optional file
name. But it should also be possible to use it without any argument to use
the backend name as file name. However, when no argument is provided, an
error is reported during the configuration parsing requesting an argument, a
file name or "use-backend-name". And This last special argument is not
documented.
So, to respect the documentation and to avoid configuration breakages, all
modes are now supported. If this directive is called with no argument or
with "use-backend-name", the backend name is use as file name for the
server-state file. Otherwise, the provided string is used.
In addition, we take care to release any previously allocated file name in
case this directive is defines multiple times in the same backend. And an
error is reported if more than one argument are defined. Finally, the
documentation is updated accordingly. Sections supporting this directive are
also mentioned.
This patch should be backported as far as 1.6.
(cherry picked from commit 583b6de68aa1a1070ac3b9c5e21605916aed2de0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 05df94b374dbbaeff5a356525a4ad9b1be0ed217)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit efcbd8efd0ea65295a570642fee6d0376c32dcc8)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 082cd495247a5002736ceb0cbadf11b17f865646)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 7f2acf2..b6e1780 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -1394,13 +1394,13 @@
else if (!strcmp(args[0], "server-state-file-name")) {
if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
err_code |= ERR_WARN;
- if (*(args[1]) == 0) {
- ha_alert("parsing [%s:%d] : '%s' expects 'use-backend-name' or a string. Got no argument\n",
- file, linenum, args[0]);
- err_code |= ERR_ALERT | ERR_FATAL;
+ if (alertif_too_many_args(1, file, linenum, args, &err_code))
goto out;
- }
- else if (!strcmp(args[1], "use-backend-name"))
+
+ free(curproxy->server_state_file_name);
+ curproxy->server_state_file_name = NULL;
+
+ if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0)
curproxy->server_state_file_name = strdup(curproxy->id);
else
curproxy->server_state_file_name = strdup(args[1]);