From c9f930c7ad6c6d5bf97c43162bf601cbf9b08801 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 22 Oct 2023 13:32:09 +0200 Subject: [PATCH] Skip registering service when if:!name matches a named svc_t The delayed matcehd works when all run/task/services provide their own unique identity, but for replacements this is sometimes not the case. Example from system/10-hotplug.conf.in: run nowarn conflict:udevd,mdev cgroup.init name:coldplug \ [S] mdevd-coldplug -- Cold plugging system vs run nowarn conflict:udevd,mdevd cgroup.init name:coldplug if:!mdevd \ [S] @pkglibexecdir@/coldplug -- Cold plugging system Here they both provide the conditions, and if the first is loaded, because we found mdevd, then we should not attempt to load this one. Signed-off-by: Joachim Wiberg --- src/service.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 411901cc..f118dac5 100644 --- a/src/service.c +++ b/src/service.c @@ -1430,6 +1430,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) char *id = NULL, *env = NULL, *cgroup = NULL; char *pre_script = NULL, *post_script = NULL; char *ready_script = NULL, *conflict = NULL; + char ident[MAX_IDENT_LEN]; char *ifstmt = NULL; char *notify = NULL; struct tty tty = { 0 }; @@ -1554,8 +1555,16 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) } name = parse_name(cmd, name); - if (!id) + strlcpy(ident, name, sizeof(ident)); + if (!id) { id = ""; + } else { + strlcat(ident, ":", sizeof(ident)); + strlcat(ident, id, sizeof(ident)); + } + + if (ifstmt && !svc_ifthen(1, ident, ifstmt)) + return 0; levels = conf_parse_runlevels(runlevels); if (runlevel != INIT_LEVEL && !ISOTHER(levels, INIT_LEVEL)) {