[systemd-devel] [systemd-commits] 5 commits - Makefile.am man/systemd-networkd-wait-online.service.xml src/libsystemd src/network src/systemd TODO units/systemd-networkd.service.in units/systemd-networkd.socket
Lennart Poettering
lennart at poettering.net
Mon Feb 2 11:59:53 PST 2015
On Mon, 02.02.15 03:00, Tom Gundersen (tomegun at 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
More information about the systemd-devel
mailing list