From a035eaa227651c2b3e4a318ccc781cf6fdc5128c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Apr 2025 08:19:43 +0200 Subject: [PATCH] netlink-socket: extend comments a bit Follow-up for 90755dac69dfb0c64e0e042aef0257c5dedb06c4. --- src/libsystemd/sd-netlink/netlink-socket.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index a6ac9789302..90522b509a2 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -161,6 +161,10 @@ static int socket_recv_message(int fd, void *buf, size_t buf_size, uint32_t *ret assert(fd >= 0); assert(peek || (buf && buf_size > 0)); + /* Note: this might return successfully, but with a zero size under some transient conditions, such + * as the reception of a non-kernel message. In such a case the passed buffer might or might not be + * modified. Caller must treat a zero return as "no message, but also not an error". */ + n = recvmsg_safe(fd, &msg, peek ? (MSG_PEEK|MSG_TRUNC) : 0); if (ERRNO_IS_NEG_TRANSIENT(n)) goto transient; @@ -179,8 +183,9 @@ static int socket_recv_message(int fd, void *buf, size_t buf_size, uint32_t *ret if (peek) { /* Drop the message. Note that we ignore ECHRNG/EXFULL errors here, which - * recvmsg_safe() returns in case the payload or cdata is truncated. Here it's quite - * likely it is truncated, because we pass a zero-sized buffer. */ + * recvmsg_safe() returns in case the payload or cdata is truncated. Given we just + * want to drop the message we also don't care if its payload or cdata was + * truncated. */ n = recvmsg_safe(fd, &msg, 0); if (n < 0 && !IN_SET(n, -ECHRNG, -EXFULL)) return (int) n; -- 2.47.3