mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
fd-util: move cmsg_close_all() to socket-util.[ch]
This call only makes sense on sockets, it's not a generic fd concept, hence let's move this over.
This commit is contained in:
committed by
Yu Watanabe
parent
030b227cec
commit
ea71d34738
@@ -606,24 +606,6 @@ int same_fd(int a, int b) {
|
||||
return fa == fb;
|
||||
}
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh) {
|
||||
assert(mh);
|
||||
|
||||
struct cmsghdr *cmsg;
|
||||
CMSG_FOREACH(cmsg, mh) {
|
||||
if (cmsg->cmsg_level != SOL_SOCKET)
|
||||
continue;
|
||||
|
||||
if (cmsg->cmsg_type == SCM_RIGHTS)
|
||||
close_many(CMSG_TYPED_DATA(cmsg, int),
|
||||
(cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
|
||||
else if (cmsg->cmsg_type == SCM_PIDFD) {
|
||||
assert(cmsg->cmsg_len == CMSG_LEN(sizeof(int)));
|
||||
safe_close(*CMSG_TYPED_DATA(cmsg, int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool fdname_is_valid(const char *s) {
|
||||
const char *p;
|
||||
|
||||
|
||||
@@ -79,8 +79,6 @@ int pack_fds(int fds[], size_t n);
|
||||
int fd_validate(int fd);
|
||||
int same_fd(int a, int b);
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh);
|
||||
|
||||
bool fdname_is_valid(const char *s);
|
||||
|
||||
int fd_get_path(int fd, char **ret);
|
||||
|
||||
@@ -1981,3 +1981,21 @@ int socket_get_cookie(int fd, uint64_t *ret) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh) {
|
||||
assert(mh);
|
||||
|
||||
struct cmsghdr *cmsg;
|
||||
CMSG_FOREACH(cmsg, mh) {
|
||||
if (cmsg->cmsg_level != SOL_SOCKET)
|
||||
continue;
|
||||
|
||||
if (cmsg->cmsg_type == SCM_RIGHTS)
|
||||
close_many(CMSG_TYPED_DATA(cmsg, int),
|
||||
(cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
|
||||
else if (cmsg->cmsg_type == SCM_PIDFD) {
|
||||
assert(cmsg->cmsg_len == CMSG_LEN(sizeof(int)));
|
||||
safe_close(*CMSG_TYPED_DATA(cmsg, int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,3 +337,5 @@ int vsock_get_local_cid(unsigned *ret);
|
||||
int netlink_socket_get_multicast_groups(int fd, size_t *ret_len, uint32_t **ret_groups);
|
||||
|
||||
int socket_get_cookie(int fd, uint64_t *ret);
|
||||
|
||||
void cmsg_close_all(struct msghdr *mh);
|
||||
|
||||
Reference in New Issue
Block a user