summaryrefslogtreecommitdiff
path: root/src/shared/dissect-image.c
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-04-13 22:54:54 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-04-15 10:29:50 +0100
commita108fcbacee859036f5613177321889bc34fd597 (patch)
treebbcd4cbddd97b9be226e4dc42c49ca0ba8422cd0 /src/shared/dissect-image.c
parent4d7a06b322d2bb01a9ce2957dbe085bb4da9f57e (diff)
downloadsystemd-a108fcbacee859036f5613177321889bc34fd597.tar.gz
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.
Diffstat (limited to 'src/shared/dissect-image.c')
-rw-r--r--src/shared/dissect-image.c13
1 files changed, 11 insertions, 2 deletions
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);