1 Star 0 Fork 98

Mingtai/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-socket-util-introduce-CMSG_SPACE_TIMEVAL-TIMESPEC-ma.patch 4.27 KB
一键复制 编辑 原始数据 按行查看 历史
From d36785cdd845710028ab033f85493572f15cab23 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 29 Aug 2021 20:50:49 +0900
Subject: [PATCH] socket-util: introduce CMSG_SPACE_TIMEVAL/TIMESPEC macro to
support additional 64bit timeval or timespec
Fixes #20482 and #20564.
(cherry picked from commit 9365e296fe281da45797af89a97627e872fc019d)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/d36785cdd845710028ab033f85493572f15cab23
---
src/basic/socket-util.h | 22 ++++++++++++++++++++++
src/journal/journald-server.c | 2 +-
src/libsystemd-network/icmp6-util.c | 2 +-
src/timesync/timesyncd-manager.c | 2 +-
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index f92e425fd6..09e606614c 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -277,6 +277,28 @@ static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
int socket_bind_to_ifname(int fd, const char *ifname);
int socket_bind_to_ifindex(int fd, int ifindex);
+/* Define a 64bit version of timeval/timespec in any case, even on 32bit userspace. */
+struct timeval_large {
+ uint64_t tvl_sec, tvl_usec;
+};
+struct timespec_large {
+ uint64_t tvl_sec, tvl_nsec;
+};
+
+/* glibc duplicates timespec/timeval on certain 32bit archs, once in 32bit and once in 64bit.
+ * See __convert_scm_timestamps() in glibc source code. Hence, we need additional buffer space for them
+ * to prevent from recvmsg_safe() returning -EXFULL. */
+#define CMSG_SPACE_TIMEVAL \
+ ((sizeof(struct timeval) == sizeof(struct timeval_large)) ? \
+ CMSG_SPACE(sizeof(struct timeval)) : \
+ CMSG_SPACE(sizeof(struct timeval)) + \
+ CMSG_SPACE(sizeof(struct timeval_large)))
+#define CMSG_SPACE_TIMESPEC \
+ ((sizeof(struct timespec) == sizeof(struct timespec_large)) ? \
+ CMSG_SPACE(sizeof(struct timespec)) : \
+ CMSG_SPACE(sizeof(struct timespec)) + \
+ CMSG_SPACE(sizeof(struct timespec_large)))
+
ssize_t recvmsg_safe(int sockfd, struct msghdr *msg, int flags);
int socket_get_family(int fd, int *ret);
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index a0695ec519..abd52f7c14 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1277,7 +1277,7 @@ int server_process_datagram(
* identical to NAME_MAX. For now we use that, but this should be updated one day when the final
* limit is known. */
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred)) +
- CMSG_SPACE(sizeof(struct timeval)) +
+ CMSG_SPACE_TIMEVAL +
CMSG_SPACE(sizeof(int)) + /* fd */
CMSG_SPACE(NAME_MAX) /* selinux label */) control;
diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c
index 0b8c3e4cc3..823be0f275 100644
--- a/src/libsystemd-network/icmp6-util.c
+++ b/src/libsystemd-network/icmp6-util.c
@@ -149,7 +149,7 @@ int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *ret_dst,
triple_timestamp *ret_timestamp) {
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(int)) + /* ttl */
- CMSG_SPACE(sizeof(struct timeval))) control;
+ CMSG_SPACE_TIMEVAL) control;
struct iovec iov = {};
union sockaddr_union sa = {};
struct msghdr msg = {
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 9d874cfc8a..eae14e8fb2 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -412,7 +412,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
.iov_base = &ntpmsg,
.iov_len = sizeof(ntpmsg),
};
- CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct timespec))) control;
+ CMSG_BUFFER_TYPE(CMSG_SPACE_TIMESPEC) control;
union sockaddr_union server_addr;
struct msghdr msghdr = {
.msg_iov = &iov,
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangmingtaip/systemd_1.git
git@gitee.com:yangmingtaip/systemd_1.git
yangmingtaip
systemd_1
systemd_1
master

搜索帮助