From: Marcos de Oliveira <markinholive...@gmail.com>

Users might want to pre-create an empty file for later dumping
server-states. This commit allows for that by emiting a notice in case
file is empty and a warning if file is not empty, but version is unknown

Fix partially: #2190
---
 src/server_state.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/server_state.c b/src/server_state.c
index 93dbd20f1..ebdcf3c69 100644
--- a/src/server_state.c
+++ b/src/server_state.c
@@ -522,6 +522,7 @@ static void srv_state_px_update(const struct proxy *px, int 
vsn, struct eb_root
 
 /*
  * read next line from file <f> and return the server state version if one 
found.
+ * If file is empty, then -1 is returned
  * If no version is found, then 0 is returned
  * Note that this should be the first read on <f>
  */
@@ -532,7 +533,7 @@ static int srv_state_get_version(FILE *f) {
 
        /* first character of first line of the file must contain the version 
of the export */
        if (fgets(mybuf, SRV_STATE_LINE_MAXLEN, f) == NULL)
-               return 0;
+               return -1;
 
        vsn = strtol(mybuf, &endptr, 10);
        if (endptr == mybuf || *endptr != '\n') {
@@ -806,9 +807,13 @@ void apply_server_state(void)
        }
 
        global_vsn = srv_state_get_version(f);
-       if (global_vsn == 0) {
-               ha_warning("config: Can't get version of the global server 
state file '%s'.\n",
-                          file);
+       if (global_vsn < 1) {
+               if (global_vsn == -1)
+                       ha_notice("config: Empty global server state file 
'%s'.\n",
+                                  file);
+               if (global_vsn == 0)
+                       ha_warning("config: Can't get version of the global 
server state file '%s'.\n",
+                                  file);
                goto close_globalfile;
        }
 
@@ -880,9 +885,13 @@ void apply_server_state(void)
 
                /* first character of first line of the file must contain the 
version of the export */
                local_vsn = srv_state_get_version(f);
-               if (local_vsn == 0) {
-                       ha_warning("Proxy '%s': Can't get version of the server 
state file '%s'.\n",
-                                  curproxy->id, file);
+               if (local_vsn < 1) {
+                       if (local_vsn == -1)
+                               ha_notice("Proxy '%s': Empty server state file 
'%s'.\n",
+                                          curproxy->id, file);
+                       if (local_vsn == 0)
+                               ha_warning("Proxy '%s': Can't get version of 
the server state file '%s'.\n",
+                                          curproxy->id, file);
                        goto close_localfile;
                }
 
-- 
2.25.1


Reply via email to