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 <service/mdevd/ready> \
	[S] mdevd-coldplug -- Cold plugging system

vs

    run nowarn conflict:udevd,mdevd cgroup.init name:coldplug if:!mdevd <service/mdev/running> \
	[S] @pkglibexecdir@/coldplug -- Cold plugging system

Here they both provide the <run/coldplug/*> 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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-10-22 13:37:13 +02:00
parent e2ee372b5d
commit c9f930c7ad
+10 -1
View File
@@ -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)) {