summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorAuke Kok <auke-jan.h.kok@intel.com>2012-09-13 12:34:25 -0700
committerLennart Poettering <lennart@poettering.net>2012-09-13 21:54:34 +0200
commit095b2d7ab9e7d66d44b93ab6e03ca69fd9e7020c (patch)
tree47abe2f43f09fa46d7a6d5a9d48bb076b6de6705 /src/core/load-fragment.c
parent0675cc4a02dfa3e7abc47d0c2117bf413b1d7698 (diff)
load-fragment: Expand specifiers in conditions.
Add specifier expansion to Path and String conditions. Specifier expansion for conditions will help create instance and user session units by allowing us to template conditions based on the instance or user session parameters. An example would be a system-wide user session service file that conditionally runs based on whether a user has the service configured through a configuration file in ~/.config/.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index c6422619f5..482d28b795 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -1469,6 +1469,7 @@ int config_parse_unit_condition_path(
Unit *u = data;
bool trigger, negate;
Condition *c;
+ char *p;
assert(filename);
assert(lvalue);
@@ -1483,14 +1484,19 @@ int config_parse_unit_condition_path(
if (negate)
rvalue++;
- if (!path_is_absolute(rvalue)) {
- log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, rvalue);
+ p = unit_full_printf(u, rvalue);
+ if (!p)
+ return -ENOMEM;
+
+ if (!path_is_absolute(p)) {
+ log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, p);
return 0;
}
- c = condition_new(cond, rvalue, trigger, negate);
+ c = condition_new(cond, p, trigger, negate);
if (!c)
return -ENOMEM;
+ free(p);
LIST_PREPEND(Condition, conditions, u->conditions, c);
return 0;
@@ -1510,6 +1516,7 @@ int config_parse_unit_condition_string(
Unit *u = data;
bool trigger, negate;
Condition *c;
+ char *s;
assert(filename);
assert(lvalue);
@@ -1524,9 +1531,14 @@ int config_parse_unit_condition_string(
if (negate)
rvalue++;
- c = condition_new(cond, rvalue, trigger, negate);
+ s = unit_full_printf(u, rvalue);
+ if (!s)
+ return -ENOMEM;
+
+ c = condition_new(cond, s, trigger, negate);
if (!c)
return log_oom();
+ free(s);
LIST_PREPEND(Condition, conditions, u->conditions, c);
return 0;