diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-01-14 23:04:03 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-01-14 23:04:03 +0000 |
commit | ddd67a294cb769c2935548fdd455459695024e33 (patch) | |
tree | 12cbb80b592a5f8dd5621e1355a8855a780cb9c4 | |
parent | 95ac7f17e2261158c793421603490c13e24efef3 (diff) | |
download | mdevd-ddd67a294cb769c2935548fdd455459695024e33.tar.xz |
netlink really isn't fd 0 anymore >.>
-rw-r--r-- | src/mdevd/mdevd.c | 14 |
1 files 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) |