From aedec452b9e5dd197881f2164fb205dfe8bfdcec Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Nov 2021 15:50:55 +0100 Subject: tree-wide: always use TAKE_FD() when calling rearrange_stdio() rearrange_stdio() invalidates specified fds even on failure, which means we should always invalidate the fds we pass in no matter what. Let's make this explicit by using TAKE_FD() for that everywhere. Note that in many places we such invalidation doesnt get us much behaviour-wise, since we don't use the variables anymore later. But TAKE_FD() in a way is also documentation, it encodes explicitly that the fds are invalidated here, so I think it's a good thing to always make this explicit here. --- src/import/import-common.c | 4 ++-- src/import/importd.c | 5 +++-- src/import/pull-common.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/import') diff --git a/src/import/import-common.c b/src/import/import-common.c index 247f49a855..c36105221f 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -65,7 +65,7 @@ int import_fork_tar_x(const char *path, pid_t *ret) { pipefd[1] = safe_close(pipefd[1]); - r = rearrange_stdio(pipefd[0], -1, STDERR_FILENO); + r = rearrange_stdio(TAKE_FD(pipefd[0]), -1, STDERR_FILENO); if (r < 0) { log_error_errno(r, "Failed to rearrange stdin/stdout: %m"); _exit(EXIT_FAILURE); @@ -131,7 +131,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) { pipefd[0] = safe_close(pipefd[0]); - r = rearrange_stdio(-1, pipefd[1], STDERR_FILENO); + r = rearrange_stdio(-1, TAKE_FD(pipefd[1]), STDERR_FILENO); if (r < 0) { log_error_errno(r, "Failed to rearrange stdin/stdout: %m"); _exit(EXIT_FAILURE); diff --git a/src/import/importd.c b/src/import/importd.c index 3e2d8427cb..0400d41b14 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -389,9 +389,10 @@ static int transfer_start(Transfer *t) { pipefd[0] = safe_close(pipefd[0]); - r = rearrange_stdio(t->stdin_fd, - t->stdout_fd < 0 ? pipefd[1] : t->stdout_fd, + r = rearrange_stdio(TAKE_FD(t->stdin_fd), + t->stdout_fd < 0 ? pipefd[1] : TAKE_FD(t->stdout_fd), pipefd[1]); + TAKE_FD(pipefd[1]); if (r < 0) { log_error_errno(r, "Failed to set stdin/stdout/stderr: %m"); _exit(EXIT_FAILURE); diff --git a/src/import/pull-common.c b/src/import/pull-common.c index adb366222d..d0d0c85adc 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -442,7 +442,7 @@ static int verify_gpg( gpg_pipe[1] = safe_close(gpg_pipe[1]); - r = rearrange_stdio(gpg_pipe[0], -1, STDERR_FILENO); + r = rearrange_stdio(TAKE_FD(gpg_pipe[0]), -1, STDERR_FILENO); if (r < 0) { log_error_errno(r, "Failed to rearrange stdin/stdout: %m"); _exit(EXIT_FAILURE); -- cgit v1.2.1