mirror of
https://github.com/troglobit/finit.git
synced 2026-11-20 19:41:51 +00:00
service: stop the restart counter of restart always from overflowing
The restart counter is a char, and with restart always nothing stops it. A service restarted more often than the counter ages wrapped it after 127 restarts, 255 on Arm. initctl status then showed a negative count and the back-off fell back to two seconds. Make the counter an int that stops at INT_MAX. With restart always it stops at 10, the default restart-max. The back-off peaks at half of that, and from 10 the counter ages back within the hour. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+20
-7
No files matched your search
@@ -188,6 +188,10 @@ All relevant changes are documented in this file.
|
|||||||
- Fix a command whose name starts like a service option, e.g. `logger` or
|
- Fix a command whose name starts like a service option, e.g. `logger` or
|
||||||
`pidof`. It was taken as the `log` or `pid` option and the next argument
|
`pidof`. It was taken as the `log` or `pid` option and the next argument
|
||||||
ran as the command, which also broke the `logger` example in finit.conf(5)
|
ran as the command, which also broke the `logger` example in finit.conf(5)
|
||||||
|
- Fix the restart counter of a service with `restart = "always"`, nothing
|
||||||
|
stopped it and it overflowed after 127 restarts, 255 on Arm. It now
|
||||||
|
stops at 10, where the back-off has long since peaked, and ages from
|
||||||
|
there
|
||||||
- Fix `restart = "always"` skipping the initial two second delay between
|
- Fix `restart = "always"` skipping the initial two second delay between
|
||||||
restarts, every restart waited five seconds
|
restarts, every restart waited five seconds
|
||||||
- Reject a .conf file that declares the same block title twice. The title is
|
- Reject a .conf file that declares the same block title twice. The title is
|
||||||
|
|||||||
+15
-6
@@ -3264,9 +3264,19 @@ static void service_cleanup_script(svc_t *svc)
|
|||||||
service_timeout_after(svc, svc->cleanup_tmo, service_kill_script);
|
service_timeout_after(svc, svc->cleanup_tmo, service_kill_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Saturates, restart always has no restart_max to stop the count */
|
||||||
|
static void restart_cnt_inc(svc_t *svc)
|
||||||
|
{
|
||||||
|
int *restart_cnt = (int *)&svc->restart_cnt;
|
||||||
|
int limit = svc->restart_max == -1 ? SVC_RESPAWN_MAX : INT_MAX;
|
||||||
|
|
||||||
|
if (*restart_cnt < limit)
|
||||||
|
(*restart_cnt)++;
|
||||||
|
}
|
||||||
|
|
||||||
static void service_retry(svc_t *svc)
|
static void service_retry(svc_t *svc)
|
||||||
{
|
{
|
||||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
int *restart_cnt = (int *)&svc->restart_cnt;
|
||||||
int timeout, half;
|
int timeout, half;
|
||||||
|
|
||||||
service_timeout_cancel(svc);
|
service_timeout_cancel(svc);
|
||||||
@@ -3321,7 +3331,7 @@ static void service_retry(svc_t *svc)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*restart_cnt)++;
|
restart_cnt_inc(svc);
|
||||||
|
|
||||||
dbg("%s crashed, trying to start it again, attempt %d", svc_ident(svc, NULL, 0), *restart_cnt);
|
dbg("%s crashed, trying to start it again, attempt %d", svc_ident(svc, NULL, 0), *restart_cnt);
|
||||||
if ((*restart_cnt) == 1)
|
if ((*restart_cnt) == 1)
|
||||||
@@ -3478,7 +3488,6 @@ void service_ready(svc_t *svc, int ready)
|
|||||||
*/
|
*/
|
||||||
int service_step(svc_t *svc)
|
int service_step(svc_t *svc)
|
||||||
{
|
{
|
||||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
|
||||||
int changed = 0, waiting = 0;
|
int changed = 0, waiting = 0;
|
||||||
svc_state_t old_state;
|
svc_state_t old_state;
|
||||||
cond_state_t cond;
|
cond_state_t cond;
|
||||||
@@ -3669,7 +3678,7 @@ restart:
|
|||||||
svc_set_state(svc, SVC_HALTED_STATE);
|
svc_set_state(svc, SVC_HALTED_STATE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*restart_cnt)++;
|
restart_cnt_inc(svc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3773,7 +3782,7 @@ restart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!svc->pid) {
|
if (!svc->pid) {
|
||||||
(*restart_cnt)++;
|
restart_cnt_inc(svc);
|
||||||
svc_set_state(svc, SVC_WAITING_STATE);
|
svc_set_state(svc, SVC_WAITING_STATE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4097,7 +4106,7 @@ static void service_interval_cb(uev_t *w, void *arg, int events)
|
|||||||
|
|
||||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||||
if (svc_is_daemon(svc)) {
|
if (svc_is_daemon(svc)) {
|
||||||
char *restart_cnt = (char *)&svc->restart_cnt;
|
int *restart_cnt = (int *)&svc->restart_cnt;
|
||||||
|
|
||||||
if (!svc_is_running(svc))
|
if (!svc_is_running(svc))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ typedef struct svc {
|
|||||||
int restart_tmo; /* Time before restarting a crashing service */
|
int restart_tmo; /* Time before restarting a crashing service */
|
||||||
unsigned char oncrash_action; /* Action to perform in crashed state. */
|
unsigned char oncrash_action; /* Action to perform in crashed state. */
|
||||||
char respawn; /* ttys, or services with `respawn`, never increment restart_cnt */
|
char respawn; /* ttys, or services with `respawn`, never increment restart_cnt */
|
||||||
const char restart_cnt; /* Incremented for each restart by service monitor. */
|
const int restart_cnt; /* Incremented for each restart by service monitor. */
|
||||||
|
|
||||||
union {
|
union {
|
||||||
/* services we redirect stdout/stderr to syslog (not TTYs!) */
|
/* services we redirect stdout/stderr to syslog (not TTYs!) */
|
||||||
|
|||||||
Reference in new issue
Block a user