Refactor, rename restart counter and change type to char, MAX=10

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-12-13 17:58:48 +01:00
parent 14c0d80f63
commit b8bf26b107
2 changed files with 12 additions and 12 deletions
+10 -10
View File
@@ -791,33 +791,33 @@ void service_monitor(pid_t lost)
static void service_retry(svc_t *svc)
{
int timeout;
int *restart_counter = (int *)&svc->restart_counter;
char *restart_cnt = (char *)&svc->restart_cnt;
service_timeout_cancel(svc);
if (svc->state != SVC_HALTED_STATE ||
svc->block != SVC_BLOCK_RESTARTING) {
_d("%s not crashing anymore", svc->desc);
*restart_counter = 0;
*restart_cnt = 0;
return;
}
if (*restart_counter >= RESPAWN_MAX) {
if (*restart_cnt >= RESPAWN_MAX) {
logit(LOG_ERR, "%s keeps crashing, not restarting", svc->desc);
svc_crashing(svc);
*restart_counter = 0;
*restart_cnt = 0;
service_step(svc);
return;
}
(*restart_counter)++;
(*restart_cnt)++;
_d("%s crashed, trying to start it again, attempt %d", svc->desc, *restart_counter);
_d("%s crashed, trying to start it again, attempt %d", svc->desc, *restart_cnt);
svc_unblock(svc);
service_step(svc);
/* Wait 2s for the first 5 respawns, then back off to 5s */
timeout = ((*restart_counter) <= (RESPAWN_MAX / 2)) ? 2000 : 5000;
timeout = ((*restart_cnt) <= (RESPAWN_MAX / 2)) ? 2000 : 5000;
service_timeout_after(svc, timeout, service_retry);
}
@@ -837,7 +837,7 @@ static void svc_set_state(svc_t *svc, svc_state_t new)
void service_step(svc_t *svc)
{
int err;
int *restart_counter = (int *)&svc->restart_counter;
char *restart_cnt = (char *)&svc->restart_cnt;
svc_cmd_t enabled;
svc_state_t old_state;
cond_state_t cond;
@@ -905,7 +905,7 @@ restart:
err = service_start(svc);
if (err) {
(*restart_counter)++;
(*restart_cnt)++;
if (!svc_is_inetd_conn(svc))
break;
@@ -982,7 +982,7 @@ restart:
}
if (!svc->pid) {
(*restart_counter)++;
(*restart_cnt)++;
svc_set_state(svc, SVC_READY_STATE);
break;
}
+2 -2
View File
@@ -101,8 +101,8 @@ typedef struct svc {
svc_block_t block; /* Reason that this service is currently stopped */
char cond[MAX_COND_LEN];
/* Incremented for each restart by service monitor. */
const unsigned int restart_counter;
/* Counters */
const char restart_cnt; /* Incremented for each restart by service monitor. */
/* For inetd services */
inetd_t inetd;