mirror of
https://github.com/systemd/systemd
synced 2024-09-06 08:46:19 +00:00
fdset: add new fdset_consume() helper
This commit is contained in:
parent
bdcad22e8e
commit
e829f28c1b
|
@ -80,6 +80,19 @@ int fdset_put(FDSet *s, int fd) {
|
|||
return set_put(MAKE_SET(s), FD_TO_PTR(fd));
|
||||
}
|
||||
|
||||
int fdset_consume(FDSet *s, int fd) {
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(fd >= 0);
|
||||
|
||||
r = fdset_put(s, fd);
|
||||
if (r < 0)
|
||||
safe_close(fd);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int fdset_put_dup(FDSet *s, int fd) {
|
||||
_cleanup_close_ int copy = -EBADF;
|
||||
int r;
|
||||
|
|
|
@ -13,6 +13,7 @@ FDSet* fdset_new(void);
|
|||
FDSet* fdset_free(FDSet *s);
|
||||
|
||||
int fdset_put(FDSet *s, int fd);
|
||||
int fdset_consume(FDSet *s, int fd);
|
||||
int fdset_put_dup(FDSet *s, int fd);
|
||||
|
||||
bool fdset_contains(FDSet *s, int fd);
|
||||
|
|
|
@ -334,11 +334,9 @@ int lock_main(int argc, char *argv[], void *userdata) {
|
|||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
r = fdset_put(fds, fd);
|
||||
r = fdset_consume(fds, TAKE_FD(fd));
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
TAKE_FD(fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue