diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-30 20:21:00 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-05 15:06:42 -0700 |
commit | 7410616cd9dbbec97cf98d75324da5cda2b2f7a2 (patch) | |
tree | 6d968995b3bdf961603ab4853bf078c0dbdce27c /src/core/device.c | |
parent | 6442185ab674cc202d63c18605057b9a51ca2722 (diff) |
core: rework unit name validation and manipulation logic
A variety of changes:
- Make sure all our calls distuingish OOM from other errors if OOM is
not the only error possible.
- Be much stricter when parsing escaped paths, do not accept trailing or
leading escaped slashes.
- Change unit validation to take a bit mask for allowing plain names,
instance names or template names or an combination thereof.
- Refuse manipulating invalid unit name
Diffstat (limited to 'src/core/device.c')
-rw-r--r-- | src/core/device.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/core/device.c b/src/core/device.c index f8e65b876f..2c56c5a2d2 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -279,9 +279,9 @@ static int device_add_udev_wants(Unit *u, struct udev_device *dev) { memcpy(e, word, l); e[l] = 0; - n = unit_name_mangle(e, MANGLE_NOGLOB); - if (!n) - return log_oom(); + r = unit_name_mangle(e, UNIT_NAME_NOGLOB, &n); + if (r < 0) + return log_unit_error_errno(u->id, r, "Failed to mangle unit name: %m"); r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true); if (r < 0) @@ -308,9 +308,9 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa if (!sysfs) return 0; - e = unit_name_from_path(path, ".device"); - if (!e) - return log_oom(); + r = unit_name_from_path(path, ".device", &e); + if (r < 0) + return log_unit_error_errno(u->id, r, "Failed to generate device name: %m"); u = manager_get_unit(m, e); @@ -491,6 +491,7 @@ static int device_update_found_by_sysfs(Manager *m, const char *sysfs, bool add, static int device_update_found_by_name(Manager *m, const char *path, bool add, DeviceFound found, bool now) { _cleanup_free_ char *e = NULL; Unit *u; + int r; assert(m); assert(path); @@ -498,9 +499,9 @@ static int device_update_found_by_name(Manager *m, const char *path, bool add, D if (found == DEVICE_NOT_FOUND) return 0; - e = unit_name_from_path(path, ".device"); - if (!e) - return log_oom(); + r = unit_name_from_path(path, ".device", &e); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name from device path: %m"); u = manager_get_unit(m, e); if (!u) |