mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
fd-util: add new fd_cloexec_many() helper
(cherry picked from commit ed18c22c98
)
This commit is contained in:
parent
57b4329b38
commit
36c3c4172d
@ -174,6 +174,25 @@ int fd_cloexec(int fd, bool cloexec) {
|
||||
return RET_NERRNO(fcntl(fd, F_SETFD, nflags));
|
||||
}
|
||||
|
||||
int fd_cloexec_many(const int fds[], size_t n_fds, bool cloexec) {
|
||||
int ret = 0, r;
|
||||
|
||||
assert(n_fds == 0 || fds);
|
||||
|
||||
for (size_t i = 0; i < n_fds; i++) {
|
||||
if (fds[i] < 0) /* Skip gracefully over already invalidated fds */
|
||||
continue;
|
||||
|
||||
r = fd_cloexec(fds[i], cloexec);
|
||||
if (r < 0 && ret >= 0) /* Continue going, but return first error */
|
||||
ret = r;
|
||||
else
|
||||
ret = 1; /* report if we did anything */
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
_pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) {
|
||||
assert(n_fdset == 0 || fdset);
|
||||
|
||||
|
@ -56,6 +56,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL);
|
||||
|
||||
int fd_nonblock(int fd, bool nonblock);
|
||||
int fd_cloexec(int fd, bool cloexec);
|
||||
int fd_cloexec_many(const int fds[], size_t n_fds, bool cloexec);
|
||||
|
||||
int get_max_fd(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user