On Mon, Feb 2, 2015 at 8:59 PM, Lennart Poettering <[email protected]> wrote: > On Mon, 02.02.15 03:00, Tom Gundersen ([email protected]) 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 _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
