From: Zbigniew Jędrzejewski-Szmek Date: Tue, 9 Mar 2021 16:24:57 +0000 (+0100) Subject: sd-netlink: use setsockopt_int() also for NETLINK_ADD/DROP_MEMBERSHIP X-Git-Tag: v248-rc3~17^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4fa024683c19259be356f5602124b1208b9d0f2d;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 9e8dff1a72c..05d6d3dafad 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) {