From ddd67a294cb769c2935548fdd455459695024e33 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 14 Jan 2018 23:04:03 +0000 Subject: netlink really isn't fd 0 anymore >.> --- src/mdevd/mdevd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mdevd/mdevd.c b/src/mdevd/mdevd.c index 4bfa558..660dc87 100644 --- a/src/mdevd/mdevd.c +++ b/src/mdevd/mdevd.c @@ -199,15 +199,17 @@ static inline int netlink_init (unsigned int kbufsz) struct sockaddr_nl nl = { .nl_family = AF_NETLINK, .nl_pad = 0, .nl_groups = 1, .nl_pid = 0 } ; int fd = socket_internal(AF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT, DJBUNIX_FLAG_NB|DJBUNIX_FLAG_COE) ; if (fd < 0) return -1 ; - if (bind(fd, (struct sockaddr *)&nl, sizeof(struct sockaddr_nl)) < 0 - || (setsockopt(0, SOL_SOCKET, SO_RCVBUFFORCE, &kbufsz, sizeof(unsigned int)) < 0 - && errno == EPERM - && setsockopt(0, SOL_SOCKET, SO_RCVBUF, &kbufsz, sizeof(unsigned int)) < 0)) + if (bind(fd, (struct sockaddr *)&nl, sizeof(struct sockaddr_nl)) < 0) goto err ; + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &kbufsz, sizeof(unsigned int)) < 0) { - fd_close(fd) ; - return -1 ; + if (errno != EPERM + || setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &kbufsz, sizeof(unsigned int)) < 0) goto err ; } return fd ; + + err: + fd_close(fd) ; + return -1 ; } static inline size_t netlink_read (int fd, char *s) -- cgit v1.2.3