systemd/backport-core-when-looping-over-mount-swap-names-continue-if-.patch
2023-12-18 15:30:01 +08:00

60 lines
2.7 KiB
Diff

From f564342089ab56e44bf7240d19b860f2ed003e58 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
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
(cherry picked from commit 598a6a8491abd311d36b11caf262123fbbffb2c0)
Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/f564342089ab56e44bf7240d19b860f2ed003e58
---
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 a81b1928b8..ca09cf0e1c 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 c212f1043d..02df6d8d19 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1275,16 +1275,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.27.0