mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
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.
This commit is contained in:
parent
ace212f577
commit
1355672437
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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, "/")) {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user