fsck: use execv_p_ and execl_p_

Instead of invoking find_executable on our own, use the variants of exec
provided by glibc which does this for us.
This commit is contained in:
Florian Klink
2023-04-17 19:56:06 +01:00
committed by Luca Boccassi
parent c9210b7470
commit 360c9cdc65
3 changed files with 5 additions and 30 deletions
+2 -11
View File
@@ -1693,7 +1693,6 @@ 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);
@@ -1708,14 +1707,6 @@ 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,
@@ -1726,7 +1717,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(fsck_path, fsck_path, "-aT", FORMAT_PROC_FD_PATH(node_fd), NULL);
execlp("fsck", "fsck", "-aT", FORMAT_PROC_FD_PATH(node_fd), NULL);
log_open();
log_debug_errno(errno, "Failed to execl() fsck: %m");
_exit(FSCK_OPERATIONAL_ERROR);
@@ -1734,7 +1725,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 %s: %m", fsck_path);
return log_debug_errno(exit_status, "Failed to fork off fsck: %m");
if ((exit_status & ~FSCK_ERROR_CORRECTED) != FSCK_SUCCESS) {
log_debug("fsck failed with exit status %i.", exit_status);