summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2022-09-29 18:51:03 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2022-09-30 16:01:41 +0200
commit13556724379a52951eb1977c2b7989a0159fd77c (patch)
tree88784b2757be7edb5e80af6716d8c344dab585b9 /src
parentportablectl: add --force attach/detach (diff)
downloadsystemd-13556724379a52951eb1977c2b7989a0159fd77c.tar.xz
systemd-13556724379a52951eb1977c2b7989a0159fd77c.zip
generator: skip fsck if fsck command is missing
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.
Diffstat (limited to 'src')
-rw-r--r--src/basic/path-util.c11
-rw-r--r--src/basic/path-util.h3
-rw-r--r--src/fsck/fsck.c10
-rw-r--r--src/home/homework-luks.c2
-rw-r--r--src/mount/mount-tool.c2
-rw-r--r--src/shared/dissect-image.c2
-rw-r--r--src/shared/generator.c11
-rw-r--r--src/test/test-path-util.c6
8 files changed, 37 insertions, 10 deletions
diff --git a/src/basic/path-util.c b/src/basic/path-util.c
index d8167da4f8..bf93990fde 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 8cd7f512a6..22d3632e6e 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 f5f8a10c57..595434ab57 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 0369e285a7..993a3143c9 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 dd0afc6e11..25e18d279c 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 2ea053e009..e85cebdb7d 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 681b97c6bd..bba8e1eaae 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 a26e351233..e3fcbd4513 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) {