chiark / gitweb /
sd-rtnl: don't fall over when receiving 0 bytes from the socket
[elogind.git] / src / libsystemd / sd-rtnl / rtnl-message.c
index 06a7a4b83a7636bb19d53e6ddecc599e25c4550c..f072899433ec7440f72f0c1acf9a994b461fb7ce 100644 (file)
@@ -71,8 +71,6 @@ int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type) {
         if (r < 0)
                 return r;
 
-        assert(nl_type->type == NLA_NESTED);
-
         r = message_new_empty(rtnl, &m);
         if (r < 0)
                 return r;
@@ -1352,9 +1350,11 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
                         log_debug("rtnl: no data in socket");
 
                 return (errno == EAGAIN || errno == EINTR) ? 0 : -errno;
-        } else if (r == 0)
-                /* connection was closed by the kernel */
-                return -ECONNRESET;
+        } else if (r == 0) {
+                /* connection was closed by the kernel? */
+                log_warning("rtnl: ignoring empty message");
+                return 0;
+        }
 
         for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
                 if (cmsg->cmsg_level == SOL_SOCKET &&
@@ -1366,7 +1366,7 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
                         if (ucred->pid == 0)
                                 auth = true;
                         else
-                                log_debug("rtnl: ignoring message from pid %u", ucred->pid);
+                                log_debug("rtnl: ignoring message from PID "PID_FMT, ucred->pid);
                 } else if (cmsg->cmsg_level == SOL_NETLINK &&
                            cmsg->cmsg_type == NETLINK_PKTINFO &&
                            cmsg->cmsg_len == CMSG_LEN(sizeof(struct nl_pktinfo))) {
@@ -1476,7 +1476,7 @@ int socket_read_message(sd_rtnl *rtnl) {
                 r = type_system_get_type(NULL, &nl_type, new_msg->nlmsg_type);
                 if (r < 0) {
                         if (r == -ENOTSUP)
-                                log_debug("sd-rtnl: ignored message with unknown type: %u",
+                                log_debug("sd-rtnl: ignored message with unknown type: %i",
                                           new_msg->nlmsg_type);
 
                         continue;