Skip to content

Commit 34bf9a7

Browse files
committed
Fix #467: TTY services stuck in restart state after non-zero exit
When a TTY exited with non-zero code (e.g., user with shell=/sbin/false), it would enter restart state but never recover, requiring manual restart. The throttling logic from commit f0032ab had two issues: 1. Duplicate exit code check in service_retry() created infinite timer loop 2. TTYs lacked default restart_tmo, causing timer to never start Fix by removing duplicate check and ensuring TTYs get a 2-second default restart_tmo for proper throttling. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent bb111f9 commit 34bf9a7

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

src/service.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,15 +2194,20 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
21942194
/* only set forking based on pidfile if user supplied pid: option */
21952195
if (pid && svc->pidfile[0] == '!')
21962196
svc->forking = 1;
2197+
}
21972198

2198-
if (svc->restart_tmo == 0) {
2199-
if (svc_is_forking(svc))
2200-
svc->restart_tmo = 2000;
2201-
else
2202-
svc->restart_tmo = 1;
2203-
}
2199+
/* Set default restart_tmo for services and TTYs that can restart */
2200+
if (svc_is_daemon(svc) && svc->restart_tmo == 0) {
2201+
if (svc_is_forking(svc))
2202+
svc->restart_tmo = 2000;
2203+
else
2204+
svc->restart_tmo = 1;
22042205
}
22052206

2207+
/* TTYs need a longer default to throttle errors (e.g., missing device) */
2208+
if (svc_is_tty(svc) && svc->restart_tmo == 0)
2209+
svc->restart_tmo = 2000;
2210+
22062211
/* Set configured limits */
22072212
memcpy(svc->rlimit, rlimit, sizeof(svc->rlimit));
22082213

@@ -2631,7 +2636,6 @@ static void service_cleanup_script(svc_t *svc)
26312636
static void service_retry(svc_t *svc)
26322637
{
26332638
char *restart_cnt = (char *)&svc->restart_cnt;
2634-
int rc = WEXITSTATUS(svc->status);
26352639
int timeout;
26362640

26372641
service_timeout_cancel(svc);
@@ -2641,17 +2645,10 @@ static void service_retry(svc_t *svc)
26412645

26422646
if (svc->respawn) {
26432647
/*
2644-
* Non-zero exit indicates an error that may not be resolved
2645-
* by immediate retry. Add delay to prevent busy-loop and to
2646-
* rate-limit retries, e.g. when TTY device doesn't exist.
2648+
* Respawn services (TTYs) that exited with non-zero status
2649+
* have already been delayed in the SVC_RUNNING_STATE handler.
2650+
* Just restart now.
26472651
*/
2648-
if (WIFEXITED(svc->status) && rc != 0) {
2649-
dbg("%s exited with error %d, delaying respawn ...",
2650-
svc_ident(svc, NULL, 0), rc);
2651-
service_timeout_after(svc, svc->restart_tmo, service_retry);
2652-
return;
2653-
}
2654-
26552652
dbg("%s crashed/exited, respawning ...", svc_ident(svc, NULL, 0));
26562653
svc_unblock(svc);
26572654
service_step(svc);

0 commit comments

Comments
 (0)