| 146 | } |
| 147 | |
| 148 | void waybar::modules::Network::createEventSocket() { |
| 149 | ev_sock_ = nl_socket_alloc(); |
| 150 | nl_socket_disable_seq_check(ev_sock_); |
| 151 | nl_socket_modify_cb(ev_sock_, NL_CB_VALID, NL_CB_CUSTOM, handleEvents, this); |
| 152 | nl_socket_modify_cb(ev_sock_, NL_CB_FINISH, NL_CB_CUSTOM, handleEventsDone, this); |
| 153 | auto groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR; |
| 154 | nl_join_groups(ev_sock_, groups); // Deprecated |
| 155 | if (nl_connect(ev_sock_, NETLINK_ROUTE) != 0) { |
| 156 | throw std::runtime_error("Can't connect network socket"); |
| 157 | } |
| 158 | if (nl_socket_set_nonblocking(ev_sock_)) { |
| 159 | throw std::runtime_error("Can't set non-blocking on network socket"); |
| 160 | } |
| 161 | nl_socket_add_memberships(ev_sock_, RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR, 0); |
| 162 | if (!config_["interface"].isString()) { |
| 163 | nl_socket_add_memberships(ev_sock_, RTNLGRP_IPV4_ROUTE, RTNLGRP_IPV6_ROUTE, 0); |
| 164 | } |
| 165 | |
| 166 | efd_ = epoll_create1(EPOLL_CLOEXEC); |
| 167 | if (efd_ < 0) { |
| 168 | throw std::runtime_error("Can't create epoll"); |
| 169 | } |
| 170 | { |
| 171 | ev_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
| 172 | struct epoll_event event; |
| 173 | memset(&event, 0, sizeof(event)); |
| 174 | event.events = EPOLLIN | EPOLLET; |
| 175 | event.data.fd = ev_fd_; |
| 176 | if (epoll_ctl(efd_, EPOLL_CTL_ADD, ev_fd_, &event) == -1) { |
| 177 | throw std::runtime_error("Can't add epoll event"); |
| 178 | } |
| 179 | } |
| 180 | { |
| 181 | auto fd = nl_socket_get_fd(ev_sock_); |
| 182 | struct epoll_event event; |
| 183 | memset(&event, 0, sizeof(event)); |
| 184 | event.events = EPOLLIN | EPOLLET | EPOLLRDHUP; |
| 185 | event.data.fd = fd; |
| 186 | if (epoll_ctl(efd_, EPOLL_CTL_ADD, fd, &event) == -1) { |
| 187 | throw std::runtime_error("Can't add epoll event"); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | void waybar::modules::Network::createInfoSocket() { |
| 193 | sock_ = nl_socket_alloc(); |
nothing calls this directly
no outgoing calls
no test coverage detected