From a108fcbacee859036f5613177321889bc34fd597 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 13 Apr 2023 22:54:54 +0200 Subject: fsck: look for fsck binary not just in /sbin This removes remaining hardcoded occurences of `/sbin/fsck`, and instead uses `find_executable` to find `fsck`. We also use `fsck_exists_for_fstype` to check for the `fsck.*` executable, which also checks in `$PATH`, so it's fair to assume fsck itself is also available. --- src/shared/dissect-image.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/shared/dissect-image.c') diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 46c42cfc95..b7c049e4c3 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1693,6 +1693,7 @@ static int is_loop_device(const char *path) { static int run_fsck(int node_fd, const char *fstype) { int r, exit_status; pid_t pid; + _cleanup_free_ char *fsck_path = NULL; assert(node_fd >= 0); assert(fstype); @@ -1707,6 +1708,14 @@ static int run_fsck(int node_fd, const char *fstype) { return 0; } + r = find_executable("fsck", &fsck_path); + /* We proceed anyway if we can't determine whether the fsck + * binary for some specific fstype exists, + * but the lack of the main fsck binary should be considered + * an error. */ + if (r < 0) + return log_error_errno(r, "Cannot find fsck binary: %m"); + r = safe_fork_full( "(fsck)", NULL, @@ -1717,7 +1726,7 @@ static int run_fsck(int node_fd, const char *fstype) { return log_debug_errno(r, "Failed to fork off fsck: %m"); if (r == 0) { /* Child */ - execl("/sbin/fsck", "/sbin/fsck", "-aT", FORMAT_PROC_FD_PATH(node_fd), NULL); + execl(fsck_path, fsck_path, "-aT", FORMAT_PROC_FD_PATH(node_fd), NULL); log_open(); log_debug_errno(errno, "Failed to execl() fsck: %m"); _exit(FSCK_OPERATIONAL_ERROR); @@ -1725,7 +1734,7 @@ static int run_fsck(int node_fd, const char *fstype) { exit_status = wait_for_terminate_and_check("fsck", pid, 0); if (exit_status < 0) - return log_debug_errno(exit_status, "Failed to fork off /sbin/fsck: %m"); + return log_debug_errno(exit_status, "Failed to fork off %s: %m", fsck_path); if ((exit_status & ~FSCK_ERROR_CORRECTED) != FSCK_SUCCESS) { log_debug("fsck failed with exit status %i.", exit_status); -- cgit v1.2.1