diff --git a/src/basic/path-util.c b/src/basic/path-util.c index d8167da4f84..bf93990fde1 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -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); } diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 8cd7f512a65..22d3632e6ef 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -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 diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index f5f8a10c570..595434ab571 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -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"); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 0369e285a70..993a3143c90 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -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) { diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index dd0afc6e111..25e18d279cb 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -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) { diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 2ea053e009a..e85cebdb7d1 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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; diff --git a/src/shared/generator.c b/src/shared/generator.c index 681b97c6bd5..bba8e1eaae5 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -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, "/")) { diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index a26e3512337..e3fcbd45136 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -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) {