]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-netlink/netlink-socket.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / libsystemd / sd-netlink / netlink-socket.c
index 3474ad9ddb1b4c0a11b49be1fe7d84ac5d12ee80..432e8e8c06c9b93529751445a58d1678e47bb521 100644 (file)
@@ -1,22 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2013 Tom Gundersen <teg@jklm.no>
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
 
 #include <netinet/in.h>
 #include <stdbool.h>
@@ -27,6 +9,7 @@
 #include "alloc-util.h"
 #include "fd-util.h"
 #include "format-util.h"
+#include "io-util.h"
 #include "missing.h"
 #include "netlink-internal.h"
 #include "netlink-types.h"
@@ -106,11 +89,11 @@ static int broadcast_groups_get(sd_netlink *nl) {
 
 int socket_bind(sd_netlink *nl) {
         socklen_t addrlen;
-        int r, one = 1;
+        int r;
 
-        r = setsockopt(nl->fd, SOL_NETLINK, NETLINK_PKTINFO, &one, sizeof(one));
+        r = setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_PKTINFO, true);
         if (r < 0)
-                return -errno;
+                return r;
 
         addrlen = sizeof(nl->sockaddr);
 
@@ -352,8 +335,7 @@ int socket_read_message(sd_netlink *rtnl) {
                             len, sizeof(uint8_t)))
                 return -ENOMEM;
 
-        iov.iov_base = rtnl->rbuffer;
-        iov.iov_len = rtnl->rbuffer_allocated;
+        iov = IOVEC_MAKE(rtnl->rbuffer, rtnl->rbuffer_allocated);
 
         /* read the pending message */
         r = socket_recv_message(rtnl->fd, &iov, &group, false);
@@ -433,8 +415,7 @@ int socket_read_message(sd_netlink *rtnl) {
                 /* push the message onto the multi-part message stack */
                 if (first)
                         m->next = first;
-                first = m;
-                m = NULL;
+                first = TAKE_PTR(m);
         }
 
         if (len > 0)
@@ -449,8 +430,7 @@ int socket_read_message(sd_netlink *rtnl) {
                 if (r < 0)
                         return r;
 
-                rtnl->rqueue[rtnl->rqueue_size++] = first;
-                first = NULL;
+                rtnl->rqueue[rtnl->rqueue_size++] = TAKE_PTR(first);
 
                 if (multi_part && (i < rtnl->rqueue_partial_size)) {
                         /* remove the message form the partial read queue */
@@ -464,15 +444,14 @@ int socket_read_message(sd_netlink *rtnl) {
                 /* we only got a partial multi-part message, push it on the
                    partial read queue */
                 if (i < rtnl->rqueue_partial_size)
-                        rtnl->rqueue_partial[i] = first;
+                        rtnl->rqueue_partial[i] = TAKE_PTR(first);
                 else {
                         r = rtnl_rqueue_partial_make_room(rtnl);
                         if (r < 0)
                                 return r;
 
-                        rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = first;
+                        rtnl->rqueue_partial[rtnl->rqueue_partial_size++] = TAKE_PTR(first);
                 }
-                first = NULL;
 
                 return 0;
         }