]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
storagetm: Check if /sys/kernel/config is a mountpoint
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 8 Feb 2025 11:44:19 +0000 (12:44 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 9 Feb 2025 15:40:45 +0000 (16:40 +0100)
Otherwise we'll fail with an unclear error later on so let's check
this first before continuing.

src/storagetm/storagetm.c

index ca8e886d37de6202edbfefd2fcda11512dad6b92..c0735c4658fc8b556295fdbe5178dd7ca34acbf8 100644 (file)
@@ -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");