From dc90f083d0e05c38b64e103d4ac984a4bba0fbea Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 8 Feb 2025 12:44:19 +0100 Subject: [PATCH] storagetm: Check if /sys/kernel/config is a mountpoint Otherwise we'll fail with an unclear error later on so let's check this first before continuing. --- src/storagetm/storagetm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/storagetm/storagetm.c b/src/storagetm/storagetm.c index ca8e886d37d..c0735c4658f 100644 --- a/src/storagetm/storagetm.c +++ b/src/storagetm/storagetm.c @@ -18,6 +18,7 @@ #include "local-addresses.h" #include "loop-util.h" #include "main-func.h" +#include "mountpoint-util.h" #include "os-util.h" #include "parse-argument.h" #include "path-util.h" @@ -1128,6 +1129,14 @@ static int run(int argc, char* argv[]) { if (r <= 0) return r; + /* If systemd-storagetm is invoked outside of it's unit /sys/kernel/config/ might not be mounted yet, + * so let's check explicitly whether it is mounted or not. */ + r = path_is_mount_point("/sys/kernel/config"); + if (r < 0) + return log_error_errno(r, "Failed to check if the configfs filesystem is mounted at /sys/kernel/config/: %m"); + if (r == 0) + return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "The configfs filesystem must be mounted at /sys/kernel/config/ to be able to use systemd-storagetm"); + r = sd_event_new(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m");