summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-04-17 14:46:05 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-04-17 19:56:06 +0100
commit360c9cdc65dc44a9d263e9f7433e7a6fbff15c9d (patch)
treebdd1eb803ace0725be939a273c70d0a9efe36d60 /src
parentc9210b74701d749c5b684cc4de517be42baa9c57 (diff)
downloadsystemd-360c9cdc65dc44a9d263e9f7433e7a6fbff15c9d.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/fsck/fsck.c11
-rw-r--r--src/home/homework-luks.c11
-rw-r--r--src/shared/dissect-image.c13
3 files changed, 5 insertions, 30 deletions
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 4d29babbd3..c0d0994e1b 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -345,7 +345,6 @@ static int run(int argc, char *argv[]) {
if (r == 0) {
char dash_c[STRLEN("-C") + DECIMAL_STR_MAX(int) + 1];
int progress_socket = -1;
- _cleanup_free_ char *fsck_path = NULL;
const char *cmdline[9];
int i = 0;
@@ -366,13 +365,7 @@ static int run(int argc, char *argv[]) {
} else
dash_c[0] = 0;
- r = find_executable("fsck", &fsck_path);
- if (r < 0) {
- log_error_errno(r, "Cannot find fsck binary: %m");
- _exit(FSCK_OPERATIONAL_ERROR);
- }
-
- cmdline[i++] = fsck_path;
+ cmdline[i++] = "fsck";
cmdline[i++] = arg_repair;
cmdline[i++] = "-T";
@@ -395,7 +388,7 @@ static int run(int argc, char *argv[]) {
cmdline[i++] = device;
cmdline[i++] = NULL;
- execv(cmdline[0], (char**) cmdline);
+ execvp(cmdline[0], (char**) cmdline);
_exit(FSCK_OPERATIONAL_ERROR);
}
diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c
index dda63d8fc0..a24e0a70b2 100644
--- a/src/home/homework-luks.c
+++ b/src/home/homework-luks.c
@@ -215,7 +215,6 @@ static int block_get_size_by_path(const char *path, uint64_t *ret) {
static int run_fsck(const char *node, const char *fstype) {
int r, exit_status;
pid_t fsck_pid;
- _cleanup_free_ char *fsck_path = NULL;
assert(node);
assert(fstype);
@@ -228,14 +227,6 @@ static int run_fsck(const char *node, 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("(fsck)",
FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_LOG|FORK_STDOUT_TO_STDERR|FORK_CLOSE_ALL_FDS,
&fsck_pid);
@@ -243,7 +234,7 @@ static int run_fsck(const char *node, const char *fstype) {
return r;
if (r == 0) {
/* Child */
- execl(fsck_path, fsck_path, "-aTl", node, NULL);
+ execlp("fsck", "fsck", "-aTl", node, NULL);
log_open();
log_error_errno(errno, "Failed to execute fsck: %m");
_exit(FSCK_OPERATIONAL_ERROR);
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index b7c049e4c3..6bf6636ba3 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -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);