1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-03-09 17:24:57 +01:00
parent 64a65bab59
commit 4fa024683c

View 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) {