From 4894580e8b6049913f8db02c500aaff42fc7c74c Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 5 Feb 2023 01:35:39 +0100 Subject: [PATCH] Fix issue where env:/pre:/post:/etc. is removed from a service stanza This issue was found when the test pre-post-serv.sh suddnely started failing, unclear how it could ever have worked before considering the nature of this patch. The trick here is when reloading a service like this: service env:/etc/env serv -np -e foo:bar into this: service pre:/bin/pre.sh serv -np In the second the env: has been removed and pre: added. But with Finit prior to this patch, env: was kept leading to unintended behavior. The same goes for the other options included in this patch. Signed-off-by: Joachim Wiberg --- src/service.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/service.c b/src/service.c index f9024712..8b952452 100644 --- a/src/service.c +++ b/src/service.c @@ -1636,16 +1636,28 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) if (halt) parse_sighalt(svc, halt); + else + svc->sighalt = svc_is_tty(svc) ? SIGHUP : SIGTERM; if (delay) parse_killdelay(svc, delay); + else + svc->killdelay = SVC_TERM_TIMEOUT; if (pre_script) parse_script("pre", pre_script, svc->pre_script, sizeof(svc->pre_script)); + else + memset(svc->pre_script, 0, sizeof(svc->pre_script)); if (post_script) parse_script("post", post_script, svc->post_script, sizeof(svc->post_script)); + else + memset(svc->post_script, 0, sizeof(svc->post_script)); if (ready_script) parse_script("ready", ready_script, svc->ready_script, sizeof(svc->ready_script)); + else + memset(svc->ready_script, 0, sizeof(svc->ready_script)); if (log) parse_log(svc, log); + else + svc->log.enabled = 0; if (notify) { int type = parse_notify(notify); @@ -1663,6 +1675,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) snprintf(svc->desc, sizeof(svc->desc), "Getty on %s", svc->dev); if (env) parse_env(svc, env); + else + memset(svc->env, 0, sizeof(svc->env)); if (file) strlcpy(svc->file, file, sizeof(svc->file)); svc->manual = manual;