MINOR: server: change srv_op_st_chg_cause storage type
This one is greatly inspired by "MINOR: server: change adm_st_chg_cause storage type".
While looking at current srv_op_st_chg_cause usage, it was clear that
the struct needed some cleanup since some leftovers from asynchronous server
state change updates were left behind and resulted in some useless code
duplication, and making the whole thing harder to maintain.
Two observations were made:
- by tracking down srv_set_{running, stopped, stopping} usage,
we can see that the <reason> argument is always a fixed statically
allocated string.
- check-related state change context (duration, status, code...) is
not used anymore since srv_append_status() directly extracts the
values from the server->check. This is pure legacy from when
the state changes were applied asynchronously.
To prevent code duplication, useless string copies and make the reason/cause
more exportable, we store it as an enum now, and we provide
srv_op_st_chg_cause() function to fetch the related description string.
HEALTH and AGENT causes (check related) are now explicitly identified to
make consumers like srv_append_op_chg_cause() able to fetch checks info
from the server itself if they need to.
diff --git a/src/server_state.c b/src/server_state.c
index e0a1373..677de88 100644
--- a/src/server_state.c
+++ b/src/server_state.c
@@ -244,7 +244,7 @@
switch (srv_op_state) {
case SRV_ST_STOPPED:
srv->check.health = 0;
- srv_set_stopped(srv, "changed from server-state after a reload", NULL);
+ srv_set_stopped(srv, SRV_OP_STCHGC_STATEFILE);
break;
case SRV_ST_STARTING:
/* If rise == 1 there is no STARTING state, let's switch to
@@ -252,7 +252,7 @@
*/
if (srv->check.rise == 1) {
srv->check.health = srv->check.rise + srv->check.fall - 1;
- srv_set_running(srv, "", NULL);
+ srv_set_running(srv, SRV_OP_STCHGC_NONE);
break;
}
if (srv->check.health < 1 || srv->check.health >= srv->check.rise)
@@ -265,17 +265,17 @@
*/
if (srv->check.fall == 1) {
srv->check.health = 0;
- srv_set_stopped(srv, "changed from server-state after a reload", NULL);
+ srv_set_stopped(srv, SRV_OP_STCHGC_STATEFILE);
break;
}
if (srv->check.health < srv->check.rise ||
srv->check.health > srv->check.rise + srv->check.fall - 2)
srv->check.health = srv->check.rise;
- srv_set_stopping(srv, "changed from server-state after a reload", NULL);
+ srv_set_stopping(srv, SRV_OP_STCHGC_STATEFILE);
break;
case SRV_ST_RUNNING:
srv->check.health = srv->check.rise + srv->check.fall - 1;
- srv_set_running(srv, "", NULL);
+ srv_set_running(srv, SRV_OP_STCHGC_NONE);
break;
}