Add support for if:[!]ident and ifdef:[!]ident for run/task/services

Conditional loading of stanza depending on ident is already loaded.  The
if: checks as in-band while ifdef: checks out-of-band, i.e., post eval.

The optional leading '!' negates the comparison, if NOT foo then ...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2023-02-28 00:49:55 +01:00
1 parent ed383eaaa6
commit fa71f97dcf
5 files changed
+72

No files matched your search

+26
View File
@@ -686,6 +686,32 @@ int svc_conflicts(svc_t *svc)
return rc;
}
int svc_ifthen(const char *ident, const char *stmt)
{
int not = 0;
svc_t *svc;
if (!stmt || !stmt[0])
return 1;
if (stmt[0] == '!') {
stmt++;
not++;
}
svc = svc_find_by_str(stmt);
if (not && svc) {
dbg("skipping %s, %s already loaded.", ident, svc_ident(svc, NULL, 0));
return 0;
}
if (!not && !svc) {
dbg("skipping %s, %s not available.", ident, stmt);
return 0;
}
return 1;
}
/* break up "job:id job:id job:id ..." into several "job:id" tokens */
static char *tokstr(char *str, size_t len)
{