summaryrefslogtreecommitdiff
path: root/src/basic/fd-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-03-22 17:04:29 +0100
committerLennart Poettering <lennart@poettering.net>2018-03-22 20:30:40 +0100
commitc10d6bdb891881f68471dabd8100ea6021e6cdbb (patch)
tree99f77908217b88a1b49c1ef23d1e27c493ba30e4 /src/basic/fd-util.c
parent2f4cefe6ce00a38988830e88f7b16acfb6b21b3c (diff)
downloadsystemd-c10d6bdb891881f68471dabd8100ea6021e6cdbb.tar.gz
macro: introduce new TAKE_FD() macro
This is similar to TAKE_PTR() but operates on file descriptors, and thus assigns -1 to the fd parameter after returning it. Removes 60 lines from our codebase. Pretty good too I think.
Diffstat (limited to 'src/basic/fd-util.c')
-rw-r--r--src/basic/fd-util.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c
index 6d7875361c..0726aac38c 100644
--- a/src/basic/fd-util.c
+++ b/src/basic/fd-util.c
@@ -484,10 +484,7 @@ int acquire_data_fd(const void *data, size_t size, unsigned flags) {
if (r < 0)
return r;
- r = fd;
- fd = -1;
-
- return r;
+ return TAKE_FD(fd);
}
try_pipe:
@@ -524,10 +521,7 @@ try_pipe:
(void) fd_nonblock(pipefds[0], false);
- r = pipefds[0];
- pipefds[0] = -1;
-
- return r;
+ return TAKE_FD(pipefds[0]);
}
try_dev_shm: