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.
This commit is contained in:
Lennart Poettering
2018-03-22 20:30:40 +01:00
parent 2f4cefe6ce
commit c10d6bdb89
25 changed files with 64 additions and 130 deletions
+2 -8
View File
@@ -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: