X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fload-fragment.c;h=2b5c8e70dd29bf60699f3a5719b9c6653655a426;hb=6e8ebcc7de321bac0ba494365a85a19040654405;hp=b22955b4244687bc9c3009bdc879275d50319c38;hpb=169c1bda807d183a362b47efe0b5b56e9320e430;p=elogind.git diff --git a/src/load-fragment.c b/src/load-fragment.c index b22955b42..2b5c8e70d 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -1400,6 +1400,67 @@ static int config_parse_ip_tos( return 0; } +static int config_parse_condition_path( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + Unit *u = data; + bool negate; + Condition *c; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if ((negate = rvalue[0] == '!')) + rvalue++; + + if (!path_is_absolute(rvalue)) { + log_error("[%s:%u] Path in condition not absolute: %s", filename, line, rvalue); + return 0; + } + + if (!(c = condition_new(CONDITION_PATH_EXISTS, rvalue, negate))) + return -ENOMEM; + + LIST_PREPEND(Condition, conditions, u->meta.conditions, c); + return 0; +} + +static int config_parse_condition_kernel( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + Unit *u = data; + bool negate; + Condition *c; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if ((negate = rvalue[0] == '!')) + rvalue++; + + if (!(c = condition_new(CONDITION_KERNEL_COMMAND_LINE, rvalue, negate))) + return -ENOMEM; + + LIST_PREPEND(Condition, conditions, u->meta.conditions, c); + return 0; +} + static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); #define FOLLOW_MAX 8 @@ -1571,6 +1632,8 @@ static void dump_items(FILE *f, const ConfigItem *items) { { config_parse_path_unit, "UNIT" }, { config_parse_notify_access, "ACCESS" }, { config_parse_ip_tos, "TOS" }, + { config_parse_condition_path, "CONDITION" }, + { config_parse_condition_kernel, "CONDITION" }, }; assert(f); @@ -1692,6 +1755,8 @@ static int load_from_path(Unit *u, const char *path) { { "DefaultDependencies", config_parse_bool, &u->meta.default_dependencies, "Unit" }, { "IgnoreDependencyFailure",config_parse_bool, &u->meta.ignore_dependency_failure, "Unit" }, { "JobTimeoutSec", config_parse_usec, &u->meta.job_timeout, "Unit" }, + { "ConditionPathExists", config_parse_condition_path, u, "Unit" }, + { "ConditionKernelCommandLine", config_parse_condition_kernel, u, "Unit" }, { "PIDFile", config_parse_path, &u->service.pid_file, "Service" }, { "ExecStartPre", config_parse_exec, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" }, @@ -1885,7 +1950,7 @@ static int load_from_path(Unit *u, const char *path) { } if (null_or_empty(&st)) - u->meta.load_state = UNIT_BANNED; + u->meta.load_state = UNIT_MASKED; else { /* Now, parse the file contents */ if ((r = config_parse(filename, f, sections, items, false, u)) < 0)