diff --git a/src/service.c b/src/service.c index 2a18fbe2..87aac7df 100644 --- a/src/service.c +++ b/src/service.c @@ -1395,7 +1395,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 *ifdef = NULL, *ifident = NULL; + char *ifdef = NULL, *ifstmt = NULL; char *notify = NULL; struct tty tty = { 0 }; char *dev = NULL; @@ -1509,7 +1509,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) else if (MATCH_CMD(cmd, "conflict:", arg)) conflict = arg; else if (MATCH_CMD(cmd, "if:", arg)) - ifident = arg; + ifstmt = arg; else if (MATCH_CMD(cmd, "ifdef:", arg)) ifdef = arg; else @@ -1525,7 +1525,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) if (!id) id = ""; - if (ifident) { + if (ifstmt) { char ident[MAX_IDENT_LEN]; if (id[0]) { @@ -1533,7 +1533,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) } else strlcpy(ident, name, sizeof(ident)); - if (!svc_ifthen(ident, ifident)) + if (!svc_ifthen(ident, ifstmt)) return 0; } diff --git a/src/svc.c b/src/svc.c index 3e83fb2b..eb76765d 100644 --- a/src/svc.c +++ b/src/svc.c @@ -694,6 +694,32 @@ int svc_ifthen(const char *ident, const char *stmt) if (!stmt || !stmt[0]) return 1; + if (stmt[0] == '<') { + enum cond_state cond; + char *ptr = ++stmt; + int i = 0; + + if (stmt[0] == '!') { + stmt++; + not++; + } + + while (ptr[i] != '>' && ptr[i] != 0) + i++; + ptr[i] = 0; + + cond = cond_get(stmt); + if (not && cond == COND_ON) { + dbg("skipping %s, cond %s is on", ident, stmt); + return 0; + } + if (!not && cond == COND_OFF) { + dbg("skipping %s, cond %s is off", ident, stmt); + return 0; + } + return 1; + } + if (stmt[0] == '!') { stmt++; not++;