]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: use setsockopt_int() also for NETLINK_ADD/DROP_MEMBERSHIP
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 9 Mar 2021 16:24:57 +0000 (17:24 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 9 Mar 2021 16:26:24 +0000 (17:26 +0100)
We use 'unsigned' as the type, but netlink(7) says the type is 'int'.
It doesn't really matter, since they are both the same size. Let's use
our helper to shorten the code a bit.

src/libsystemd/sd-netlink/netlink-socket.c

index 9e8dff1a72c9dd1140e6a4f4f891405abe8615b8..05d6d3dafad314d79e217c4ca4377dbb37df2d1d 100644 (file)
@@ -130,17 +130,12 @@ static int broadcast_group_set_ref(sd_netlink *nl, unsigned group, unsigned n_re
 }
 
 static int broadcast_group_join(sd_netlink *nl, unsigned group) {
-        int r;
-
         assert(nl);
         assert(nl->fd >= 0);
         assert(group > 0);
 
-        r = setsockopt(nl->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group));
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        /* group is "unsigned", but netlink(7) says the argument for NETLINK_ADD_MEMBERSHIP is "int" */
+        return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, group);
 }
 
 int socket_broadcast_group_ref(sd_netlink *nl, unsigned group) {
@@ -173,8 +168,6 @@ int socket_broadcast_group_ref(sd_netlink *nl, unsigned group) {
 }
 
 static int broadcast_group_leave(sd_netlink *nl, unsigned group) {
-        int r;
-
         assert(nl);
         assert(nl->fd >= 0);
         assert(group > 0);
@@ -182,11 +175,8 @@ static int broadcast_group_leave(sd_netlink *nl, unsigned group) {
         if (nl->broadcast_group_dont_leave)
                 return 0;
 
-        r = setsockopt(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, &group, sizeof(group));
-        if (r < 0)
-                return -errno;
-
-        return 0;
+        /* group is "unsigned", but netlink(7) says the argument for NETLINK_DROP_MEMBERSHIP is "int" */
+        return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group);
 }
 
 int socket_broadcast_group_unref(sd_netlink *nl, unsigned group) {