diff options
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-rtnl/sd-rtnl.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c index 543bad9f4f..4ee360c0a8 100644 --- a/src/libsystemd/sd-rtnl/sd-rtnl.c +++ b/src/libsystemd/sd-rtnl/sd-rtnl.c @@ -75,8 +75,27 @@ static bool rtnl_pid_changed(sd_rtnl *rtnl) { return rtnl->original_pid != getpid(); } -int sd_rtnl_open(sd_rtnl **ret, uint32_t groups) { +static int rtnl_compute_groups_ap(uint32_t *_groups, unsigned n_groups, va_list ap) { + uint32_t groups = 0; + unsigned i; + + for (i = 0; i < n_groups; i++) { + unsigned group; + + group = va_arg(ap, unsigned); + assert_return(group < 32, -EINVAL); + + groups |= group ? (1 << (group - 1)) : 0; + } + + *_groups = groups; + + return 0; +} + +int sd_rtnl_open(sd_rtnl **ret, unsigned n_groups, ...) { _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL; + va_list ap; socklen_t addrlen; int r, one = 1; @@ -93,7 +112,11 @@ int sd_rtnl_open(sd_rtnl **ret, uint32_t groups) { if (setsockopt(rtnl->fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) return -errno; - rtnl->sockaddr.nl.nl_groups = groups; + va_start(ap, n_groups); + r = rtnl_compute_groups_ap(&rtnl->sockaddr.nl.nl_groups, n_groups, ap); + va_end(ap); + if (r < 0) + return r; addrlen = sizeof(rtnl->sockaddr); |