From 4fa024683c19259be356f5602124b1208b9d0f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 9 Mar 2021 17:24:57 +0100 Subject: [PATCH] sd-netlink: use setsockopt_int() also for NETLINK_ADD/DROP_MEMBERSHIP 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 | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 9e8dff1a72..05d6d3dafa 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -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) {