From 3b601d0115935944fa121234d29852074926ecb9 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 11 Nov 2022 16:35:58 +0100 Subject: [PATCH] Fix issue with services suddenly converting to 'forking' type When a service starts up the pidfile.so plugin automatically detects any new pidfiles that show up in the system. If it finds a matching service which does not have a custom configured pidfile, it auto-assigns the detected pidfile to the service. However, when the user later calls `initctl reload` to update the running configuration set, Finit service_register() mistakenly will set the service to forking since it now suddenly has a pidfile ... The new style way of configuring a forking service is to set the type:forking option. The old compat way was to set `pid:!/path/to/pidfile`, so in service_register() we must be very careful not to interpret the registered pidfile as confiugred by the user -- i.e., check the pid option. Bug #313 Signed-off-by: Joachim Wiberg --- src/service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index f2a7e5cf..cea1673d 100644 --- a/src/service.c +++ b/src/service.c @@ -1619,7 +1619,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) if (pid && pid_file_parse(svc, pid)) logit(LOG_WARNING, "%s: service has invalid 'pid:' config: %s", svc->name, pid); - if (svc->pidfile[0] == '!') + /* only set forking based on pidfile if user supplied pid: option */ + if (pid && svc->pidfile[0] == '!') svc->forking = 1; if (svc->restart_tmo == 0) {