From 598a6a8491abd311d36b11caf262123fbbffb2c0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Jun 2021 22:20:55 +0200 Subject: [PATCH] core: when looping over mount/swap names, continue if we find one which doesn't translate to a valid unit name --- src/core/swap.c | 3 +++ src/core/unit.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/swap.c b/src/core/swap.c index 74da2428c29..ecf42ad1196 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1448,6 +1448,9 @@ int swap_process_device_new(Manager *m, sd_device *dev) { int q; q = unit_name_from_path(devlink, ".swap", &n); + if (IN_SET(q, -EINVAL, -ENAMETOOLONG)) /* If name too long or otherwise not convertible to + * unit name, we can't manage it */ + continue; if (q < 0) return q; diff --git a/src/core/unit.c b/src/core/unit.c index dbdf7d9b372..4332263a9a6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1473,16 +1473,17 @@ static int unit_add_mount_dependencies(Unit *u) { Unit *m; r = unit_name_from_path(prefix, ".mount", &p); + if (IN_SET(r, -EINVAL, -ENAMETOOLONG)) + continue; /* If the path cannot be converted to a mount unit name, then it's + * not managable as a unit by systemd, and hence we don't need a + * dependency on it. Let's thus silently ignore the issue. */ if (r < 0) return r; m = manager_get_unit(u->manager, p); if (!m) { - /* Make sure to load the mount unit if - * it exists. If so the dependencies - * on this unit will be added later - * during the loading of the mount - * unit. */ + /* Make sure to load the mount unit if it exists. If so the dependencies on + * this unit will be added later during the loading of the mount unit. */ (void) manager_load_unit_prepare(u->manager, p, NULL, NULL, &m); continue; } -- 2.47.3