diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-10-26 17:12:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-11-10 19:52:41 +0100 |
commit | dcebc9bae4dcc3e844f01558c6127fc0d8745c8e (patch) | |
tree | 449ccb43ec4b8727ad2368c3e7c9bbab254e2640 /src/core/device.c | |
parent | 3ac62a0ee4db7a1f3653a0f2188ce4e1ad3360c7 (diff) | |
download | systemd-dcebc9bae4dcc3e844f01558c6127fc0d8745c8e.tar.gz |
core: when a unit template is specified in SYSTEMD_WANTS=, instantiate it with sysfs path
This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
Diffstat (limited to 'src/core/device.c')
-rw-r--r-- | src/core/device.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/core/device.c b/src/core/device.c index bfab494149..a0150751cd 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -277,11 +277,28 @@ static int device_add_udev_wants(Unit *u, struct udev_device *dev) { if (r == -ENOMEM) return log_oom(); if (r < 0) - return log_unit_error_errno(u, r, "Failed to add parse %s: %m", property); + return log_unit_error_errno(u, r, "Failed to parse property %s with value %s: %m", property, wants); - r = unit_name_mangle(word, UNIT_NAME_NOGLOB, &k); - if (r < 0) - return log_unit_error_errno(u, r, "Failed to mangle unit name \"%s\": %m", word); + if (unit_name_is_valid(word, UNIT_NAME_TEMPLATE) && DEVICE(u)->sysfs) { + _cleanup_free_ char *escaped = NULL; + + /* If the unit name is specified as template, then automatically fill in the sysfs path of the + * device as instance name, properly escaped. */ + + r = unit_name_path_escape(DEVICE(u)->sysfs, &escaped); + if (r < 0) + return log_unit_error_errno(u, r, "Failed to escape %s: %m", DEVICE(u)->sysfs); + + r = unit_name_replace_instance(word, escaped, &k); + if (r < 0) + return log_unit_error_errno(u, r, "Failed to build %s instance of template %s: %m", escaped, word); + } else { + /* If this is not a template, then let's mangle it so, that it becomes a valid unit name. */ + + r = unit_name_mangle(word, UNIT_NAME_NOGLOB, &k); + if (r < 0) + return log_unit_error_errno(u, r, "Failed to mangle unit name \"%s\": %m", word); + } r = unit_add_dependency_by_name(u, UNIT_WANTS, k, NULL, true, UNIT_DEPENDENCY_UDEV); if (r < 0) |