mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
BUG/MINOR: server-state: Ignore empty files
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 CF: Technically speaking, this patch can be backported to all stable versions. But it is better to do so to 2.8 only for now.
This commit is contained in:
parent
bd6ef51fa5
commit
122a903b94
@ -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.
|
* 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
|
* If no version is found, then 0 is returned
|
||||||
* Note that this should be the first read on <f>
|
* 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 */
|
/* first character of first line of the file must contain the version of the export */
|
||||||
if (fgets(mybuf, SRV_STATE_LINE_MAXLEN, f) == NULL)
|
if (fgets(mybuf, SRV_STATE_LINE_MAXLEN, f) == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
vsn = strtol(mybuf, &endptr, 10);
|
vsn = strtol(mybuf, &endptr, 10);
|
||||||
if (endptr == mybuf || *endptr != '\n') {
|
if (endptr == mybuf || *endptr != '\n') {
|
||||||
@ -803,9 +804,13 @@ void apply_server_state(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
global_vsn = srv_state_get_version(f);
|
global_vsn = srv_state_get_version(f);
|
||||||
if (global_vsn == 0) {
|
if (global_vsn < 1) {
|
||||||
ha_warning("config: Can't get version of the global server state file '%s'.\n",
|
if (global_vsn == -1)
|
||||||
file);
|
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;
|
goto close_globalfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,9 +878,13 @@ void apply_server_state(void)
|
|||||||
|
|
||||||
/* first character of first line of the file must contain the version of the export */
|
/* first character of first line of the file must contain the version of the export */
|
||||||
local_vsn = srv_state_get_version(f);
|
local_vsn = srv_state_get_version(f);
|
||||||
if (local_vsn == 0) {
|
if (local_vsn < 1) {
|
||||||
ha_warning("Proxy '%s': Can't get version of the server state file '%s'.\n",
|
if (local_vsn == -1)
|
||||||
curproxy->id, file);
|
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;
|
goto close_localfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user