On Mon, 02.02.15 03:00, Tom Gundersen (tome...@kemper.freedesktop.org) wrote:

>  
> +static int systemd_netlink_fd(int *ret) {
> +        int n, fd, rtnl_fd = -1;
> +
> +        n = sd_listen_fds(true);
> +        if (n <= 0)
> +                return -EINVAL;
> +
> +        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++) {
> +                if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
> +                        if (rtnl_fd >= 0)
> +                                return -EINVAL;
> +
> +                        rtnl_fd = fd;
> +                }
> +        }
> +
> +        if (rtnl_fd < 0)
> +                return -EINVAL;
> +
> +        *ret = rtnl_fd;
> +
> +        return 0;
> +}

BTW, if a function that returns an fd, can just do so as return value,
rather than as call-by-ref argument, since fds are >= 0 and errors are
< 0, and hence we can use the full "int" range then.

>  
> +int sd_rtnl_new_from_netlink(sd_rtnl **ret, int fd) {

Can't his one be folded into sd_rtnl_open_fd()? It does one more step,
invoking bind() on the fd, but if we handling double binding
correctly, then I think that would be the cleaner API?

Lennart

-- 
Lennart Poettering, Red Hat
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to