summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-07 12:24:53 +0100
committerGitHub <noreply@github.com>2022-11-07 12:24:53 +0100
commitbcb639662ed0b93b3106973f205f8b990ea862fa (patch)
treea510e0b8031706cbf46424b46d9c22bc9808c72b /src/shared
parentf10ad99ab07ca03b6190a500c49d3d76e35ab1f8 (diff)
parentf8ab781223bcb0330ee4499b879a62e84fee313e (diff)
downloadsystemd-bcb639662ed0b93b3106973f205f8b990ea862fa.tar.gz
Merge pull request #25266 from poettering/dissect-fsck-fix
dissect: fix fsck invocation
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dissect-image.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 2989d31d3c..cfa7d7e0f3 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -1327,11 +1327,11 @@ static int is_loop_device(const char *path) {
return true;
}
-static int run_fsck(const char *node, const char *fstype) {
+static int run_fsck(int node_fd, const char *fstype) {
int r, exit_status;
pid_t pid;
- assert(node);
+ assert(node_fd >= 0);
assert(fstype);
r = fsck_exists_for_fstype(fstype);
@@ -1340,16 +1340,20 @@ static int run_fsck(const char *node, const char *fstype) {
return 0;
}
if (r == 0) {
- log_debug("Not checking partition %s, as fsck for %s does not exist.", node, fstype);
+ log_debug("Not checking partition %s, as fsck for %s does not exist.", FORMAT_PROC_FD_PATH(node_fd), fstype);
return 0;
}
- r = safe_fork("(fsck)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_NULL_STDIO, &pid);
+ r = safe_fork_full(
+ "(fsck)",
+ &node_fd, 1, /* Leave the node fd open */
+ FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_NULL_STDIO|FORK_CLOEXEC_OFF,
+ &pid);
if (r < 0)
return log_debug_errno(r, "Failed to fork off fsck: %m");
if (r == 0) {
/* Child */
- execl("/sbin/fsck", "/sbin/fsck", "-aT", node, NULL);
+ execl("/sbin/fsck", "/sbin/fsck", "-aT", FORMAT_PROC_FD_PATH(node_fd), NULL);
log_open();
log_debug_errno(errno, "Failed to execl() fsck: %m");
_exit(FSCK_OPERATIONAL_ERROR);
@@ -1439,7 +1443,7 @@ static int mount_partition(
rw = m->rw && !(flags & DISSECT_IMAGE_MOUNT_READ_ONLY);
if (FLAGS_SET(flags, DISSECT_IMAGE_FSCK) && rw) {
- r = run_fsck(node, fstype);
+ r = run_fsck(m->mount_node_fd, fstype);
if (r < 0)
return r;
}