From c886ecb5cc6d5f4aa67d56e4d7b5d046ca8a9880 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Oct 2023 19:25:10 +0100 Subject: [PATCH] Add support for multiple if:!foo,!bar to skip loading of service Signed-off-by: Joachim Wiberg --- src/svc.c | 52 ++++++++++++++++++++++----------------- system/10-hotplug.conf.in | 6 ++--- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/svc.c b/src/svc.c index a5039cae..001993de 100644 --- a/src/svc.c +++ b/src/svc.c @@ -710,6 +710,7 @@ int svc_conflicts(svc_t *svc) */ int svc_ifthen(int is_conf, const char *ident, char *stmt) { + char stmts[MAX_IDENT_LEN]; int not = 0; svc_t *svc; @@ -724,39 +725,46 @@ int svc_ifthen(int is_conf, const char *ident, char *stmt) if (is_conf) return 1; - if (stmt[0] == '!') { - stmt++; - not++; - } - while (ptr[i] != '>' && ptr[i] != 0) i++; ptr[i] = 0; - cond = cond_get(stmt); - if (not && cond == COND_ON) - return 0; - if (!not && cond == COND_OFF) - return 0; + strlcpy(stmts, stmt, sizeof(stmts)); + for (stmt = strtok(stmts, ","); stmt; stmt = strtok(NULL, ","), not = 0) { + if (stmt[0] == '!') { + stmt++; + not++; + } + + cond = cond_get(stmt); + if (not && cond == COND_ON) + return 0; + if (!not && cond == COND_OFF) + return 0; + } + return 1; } if (!is_conf) return 1; - if (stmt[0] == '!') { - stmt++; - not++; - } + strlcpy(stmts, stmt, sizeof(stmts)); + for (stmt = strtok(stmts, ","); stmt; stmt = strtok(NULL, ","), not = 0) { + if (stmt[0] == '!') { + stmt++; + not++; + } - svc = svc_find_by_str(stmt); - if (not && svc) { - logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0)); - return 0; - } - if (!not && !svc) { - logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt); - return 0; + svc = svc_find_by_str(stmt); + if (not && svc) { + logit(LOG_NOTICE, "skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0)); + return 0; + } + if (!not && !svc) { + logit(LOG_NOTICE, "skipping %s, %s not available.", ident, stmt); + return 0; + } } return 1; diff --git a/system/10-hotplug.conf.in b/system/10-hotplug.conf.in index 7e40062a..fc4981c5 100644 --- a/system/10-hotplug.conf.in +++ b/system/10-hotplug.conf.in @@ -34,7 +34,7 @@ run nowarn if:udevd cgroup.init :5 [S] log udevadm settle -t 30 # (same as for plain mdev below) can be relied on as a # barrier for services that, e.g., need to probe for switchcore ports or PHYs # that require firmware loading before they show up. -service nowarn conflict:udevd,mdev cgroup.init \ +service nowarn conflict:udevd,mdev cgroup.init if:!udevd \ [S12345789] notify:s6 mdevd -O 4 -D %n -- Device event daemon (mdevd) run nowarn conflict:udevd,mdev cgroup.init name:coldplug \ [S] mdevd-coldplug -- Cold plugging system @@ -42,12 +42,12 @@ run nowarn conflict:udevd,mdev cgroup.init name:coldplug is # not an indicator of all devices having been (re)discovered and fully set up. -run nowarn conflict:udevd,mdevd cgroup.init name:coldplug if:!mdevd \ +run nowarn conflict:udevd,mdevd cgroup.init name:coldplug if:mdev \ [S] @pkglibexecdir@/coldplug -- Cold plugging system