chiark / gitweb /
sd-rtnl: read_message - don't set group if not needed
[elogind.git] / src / libsystemd / sd-rtnl / rtnl-message.c
index e7e3799286124af22b2838002dbd98af486aec86..5a719003ac354fc83cc968e0c5e0b0e4e65aa6b9 100644 (file)
@@ -20,7 +20,6 @@
 ***/
 
 #include <netinet/in.h>
-#include <netinet/ether.h>
 #include <stdbool.h>
 #include <unistd.h>
 
@@ -649,13 +648,13 @@ int sd_rtnl_message_get_family(sd_rtnl_message *m, int *family) {
                 return 0;
         }
 
-        return -ENOTSUP;
+        return -EOPNOTSUPP;
 }
 
 int sd_rtnl_message_is_broadcast(sd_rtnl_message *m) {
         assert_return(m, -EINVAL);
 
-        return !m->hdr->nlmsg_pid;
+        return m->broadcast;
 }
 
 int sd_rtnl_message_link_get_ifindex(sd_rtnl_message *m, int *ifindex) {
@@ -1431,7 +1430,7 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
         assert(fd >= 0);
         assert(iov);
 
-        r = recvmsg(fd, &msg, MSG_TRUNC | MSG_CMSG_CLOEXEC | (peek ? MSG_PEEK : 0));
+        r = recvmsg(fd, &msg, MSG_TRUNC | (peek ? MSG_PEEK : 0));
         if (r < 0) {
                 /* no data */
                 if (errno == ENOBUFS)
@@ -1467,7 +1466,7 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
                 /* not from the kernel, ignore */
                 if (peek) {
                         /* drop the message */
-                        r = recvmsg(fd, &msg, MSG_CMSG_CLOEXEC);
+                        r = recvmsg(fd, &msg, 0);
                         if (r < 0)
                                 return (errno == EAGAIN || errno == EINTR) ? 0 : -errno;
                 }
@@ -1475,7 +1474,7 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
                 return 0;
         }
 
-        if (group)
+        if (_group)
                 *_group = group;
 
         return r;
@@ -1501,7 +1500,7 @@ int socket_read_message(sd_rtnl *rtnl) {
         assert(rtnl->rbuffer_allocated >= sizeof(struct nlmsghdr));
 
         /* read nothing, just get the pending message size */
-        r = socket_recv_message(rtnl->fd, &iov, &group, true);
+        r = socket_recv_message(rtnl->fd, &iov, NULL, true);
         if (r <= 0)
                 return r;
         else
@@ -1561,7 +1560,7 @@ int socket_read_message(sd_rtnl *rtnl) {
                 /* check that we support this message type */
                 r = type_system_get_type(NULL, &nl_type, new_msg->nlmsg_type);
                 if (r < 0) {
-                        if (r == -ENOTSUP)
+                        if (r == -EOPNOTSUPP)
                                 log_debug("sd-rtnl: ignored message with unknown type: %i",
                                           new_msg->nlmsg_type);
 
@@ -1578,6 +1577,8 @@ int socket_read_message(sd_rtnl *rtnl) {
                 if (r < 0)
                         return r;
 
+                m->broadcast = !!group;
+
                 m->hdr = memdup(new_msg, new_msg->nlmsg_len);
                 if (!m->hdr)
                         return -ENOMEM;