]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
generator: skip fsck if fsck command is missing
authorJonas Kümmerlin <jonas@kuemmerlin.eu>
Thu, 29 Sep 2022 16:51:03 +0000 (18:51 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 30 Sep 2022 14:01:41 +0000 (15:01 +0100)
This is useful for systems which don't have any fsck.

We already skip emitting the fsck dependency when the fsck.$fstype helper
is missing, but fstab-generator doesn't necessarily know the fstype when
handling the root= parameter.

Previously, systemd-fsck was started for these mounts and then exited
immediately because it couldn't find the fsck.$fstype helper.

src/basic/path-util.c
src/basic/path-util.h
src/fsck/fsck.c
src/home/homework-luks.c
src/mount/mount-tool.c
src/shared/dissect-image.c
src/shared/generator.c
src/test/test-path-util.c

index d8167da4f84e85048a458d847b13e34d8f6d2798..bf93990fde1db8422f37ca8bfdf46b3a0083bff1 100644 (file)
@@ -782,14 +782,23 @@ static int executable_is_good(const char *executable) {
                                "/dev/null");
 }
 
-int fsck_exists(const char *fstype) {
+int fsck_exists(void) {
+        return executable_is_good("fsck");
+}
+
+int fsck_exists_for_fstype(const char *fstype) {
         const char *checker;
+        int r;
 
         assert(fstype);
 
         if (streq(fstype, "auto"))
                 return -EINVAL;
 
+        r = fsck_exists();
+        if (r <= 0)
+                return r;
+
         checker = strjoina("fsck.", fstype);
         return executable_is_good(checker);
 }
index 8cd7f512a6588b9f1b058556152ef328f0bc5d4e..22d3632e6ef2c4f24959bd6ab0bd1e23f6e5a87c 100644 (file)
@@ -103,7 +103,8 @@ static inline int find_executable(const char *name, char **ret_filename) {
 
 bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);
 
-int fsck_exists(const char *fstype);
+int fsck_exists(void);
+int fsck_exists_for_fstype(const char *fstype);
 
 /* Iterates through the path prefixes of the specified path, going up
  * the tree, to root. Also returns "" (and not "/"!) for the root
index f5f8a10c5701d31485c76745a742d2b224f6e8fc..595434ab571e327ebf5c5e7aacc8a3ac5a1ff2bb 100644 (file)
@@ -324,13 +324,21 @@ static int run(int argc, char *argv[]) {
         }
 
         if (sd_device_get_property_value(dev, "ID_FS_TYPE", &type) >= 0) {
-                r = fsck_exists(type);
+                r = fsck_exists_for_fstype(type);
                 if (r < 0)
                         log_device_warning_errno(dev, r, "Couldn't detect if fsck.%s may be used, proceeding: %m", type);
                 else if (r == 0) {
                         log_device_info(dev, "fsck.%s doesn't exist, not checking file system.", type);
                         return 0;
                 }
+        } else {
+                r = fsck_exists();
+                if (r < 0)
+                        log_device_warning_errno(dev, r, "Couldn't detect if the fsck command may be used, proceeding: %m");
+                else if (r == 0) {
+                        log_device_info(dev, "The fsck command does not exist, not checking file system.");
+                        return 0;
+                }
         }
 
         console = fopen("/dev/console", "we");
index 0369e285a70289bfe14d65003428bea0fb4c5c81..993a3143c9087198637bbd9029470d723805cb6c 100644 (file)
@@ -217,7 +217,7 @@ static int run_fsck(const char *node, const char *fstype) {
         assert(node);
         assert(fstype);
 
-        r = fsck_exists(fstype);
+        r = fsck_exists_for_fstype(fstype);
         if (r < 0)
                 return log_error_errno(r, "Failed to check if fsck for file system %s exists: %m", fstype);
         if (r == 0) {
index dd0afc6e1111388334863eb04aa9a1367f78106a..25e18d279cbe80846cb859b9eed1ef0b0dc1e733 100644 (file)
@@ -1497,7 +1497,7 @@ static int run(int argc, char* argv[]) {
                 arg_fsck = false;
 
         if (arg_fsck && arg_mount_type && arg_transport == BUS_TRANSPORT_LOCAL) {
-                r = fsck_exists(arg_mount_type);
+                r = fsck_exists_for_fstype(arg_mount_type);
                 if (r < 0)
                         log_warning_errno(r, "Couldn't determine whether fsck for %s exists, proceeding anyway.", arg_mount_type);
                 else if (r == 0) {
index 2ea053e009ae28a58eac78340db81ef5e2f251d9..e85cebdb7d1e9ce77ab766df7eb866bbdef17cdf 100644 (file)
@@ -1196,7 +1196,7 @@ static int run_fsck(const char *node, const char *fstype) {
         assert(node);
         assert(fstype);
 
-        r = fsck_exists(fstype);
+        r = fsck_exists_for_fstype(fstype);
         if (r < 0) {
                 log_debug_errno(r, "Couldn't determine whether fsck for %s exists, proceeding anyway.", fstype);
                 return 0;
index 681b97c6bd5f5b5cef5f105b8e1d4aad878a1340..bba8e1eaae532a8a9425516581e52f63df0075cf 100644 (file)
@@ -167,7 +167,7 @@ int generator_write_fsck_deps(
         }
 
         if (!isempty(fstype) && !streq(fstype, "auto")) {
-                r = fsck_exists(fstype);
+                r = fsck_exists_for_fstype(fstype);
                 if (r < 0)
                         log_warning_errno(r, "Checking was requested for %s, but couldn't detect if fsck.%s may be used, proceeding: %m", what, fstype);
                 else if (r == 0) {
@@ -175,6 +175,15 @@ int generator_write_fsck_deps(
                         log_debug("Checking was requested for %s, but fsck.%s does not exist.", what, fstype);
                         return 0;
                 }
+        } else {
+                r = fsck_exists();
+                if (r < 0)
+                        log_warning_errno(r, "Checking was requested for %s, but couldn't detect if the fsck command may be used, proceeding: %m", what);
+                else if (r == 0) {
+                        /* treat missing fsck as essentially OK */
+                        log_debug("Checking was requested for %s, but the fsck command does not exist.", what);
+                        return 0;
+                }
         }
 
         if (path_equal(where, "/")) {
index a26e3512337123ae578f4a8e6856ba6f610216c9..e3fcbd45136418c72df235145d9a87a4f3481f44 100644 (file)
@@ -445,10 +445,10 @@ TEST(fsck_exists) {
         assert_se(unsetenv("PATH") == 0);
 
         /* fsck.minix is provided by util-linux and will probably exist. */
-        assert_se(fsck_exists("minix") == 1);
+        assert_se(fsck_exists_for_fstype("minix") == 1);
 
-        assert_se(fsck_exists("AbCdE") == 0);
-        assert_se(fsck_exists("/../bin/") == 0);
+        assert_se(fsck_exists_for_fstype("AbCdE") == 0);
+        assert_se(fsck_exists_for_fstype("/../bin/") == 0);
 }
 
 static void test_path_make_relative_one(const char *from, const char *to, const char *expected) {