[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

Tom Gundersen teg at jklm.no
Thu Feb 12 04:39:31 PST 2015


On Mon, Feb 2, 2015 at 8:59 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> 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?

FTR: these suggestions have now been implemented in git.

Thanks!

Tom


More information about the systemd-devel mailing list