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.
This commit is contained in:
Lennart Poettering
2021-11-03 23:05:26 +00:00
committed by Luca Boccassi
parent 829b86bc0f
commit aedec452b9
11 changed files with 28 additions and 25 deletions
+2 -2
View File
@@ -38,9 +38,9 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
if (r == 0) {
char *empty_env = NULL;
safe_close(pipe_fds[0]);
pipe_fds[0] = safe_close(pipe_fds[0]);
if (rearrange_stdio(-1, pipe_fds[1], -1) < 0)
if (rearrange_stdio(-1, TAKE_FD(pipe_fds[1]), -1) < 0)
_exit(EXIT_FAILURE);
(void) close_all_fds(NULL, 0);