mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 16:34:45 +07:00
Extend conditional load support with if:<cond> and if:<!cond>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user