mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(network): retry around all getExternalInterface
This commit is contained in:
parent
9b89fc6470
commit
b05d4cd413
@ -519,8 +519,15 @@ bool waybar::modules::Network::checkInterface(struct ifinfomsg *rtif, std::strin
|
|||||||
return config_["interface"].asString() == name ||
|
return config_["interface"].asString() == name ||
|
||||||
wildcardMatch(config_["interface"].asString(), name);
|
wildcardMatch(config_["interface"].asString(), name);
|
||||||
}
|
}
|
||||||
auto external_iface = getExternalInterface();
|
// getExternalInterface may need some delay to detect external interface
|
||||||
return external_iface == rtif->ifi_index;
|
for (uint8_t tries = 0; tries < MAX_RETRY; tries += 1) {
|
||||||
|
auto external_iface = getExternalInterface();
|
||||||
|
if (external_iface > 0) {
|
||||||
|
return external_iface == rtif->ifi_index;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int waybar::modules::Network::getPreferredIface(int skip_idx) const {
|
int waybar::modules::Network::getPreferredIface(int skip_idx) const {
|
||||||
@ -550,9 +557,13 @@ int waybar::modules::Network::getPreferredIface(int skip_idx) const {
|
|||||||
return ifid;
|
return ifid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ifid = getExternalInterface(skip_idx);
|
// getExternalInterface may need some delay to detect external interface
|
||||||
if (ifid > 0) {
|
for (uint8_t tries = 0; tries < MAX_RETRY; tries += 1) {
|
||||||
return ifid;
|
ifid = getExternalInterface(skip_idx);
|
||||||
|
if (ifid > 0) {
|
||||||
|
return ifid;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -597,23 +608,25 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
net->clearIface();
|
net->clearIface();
|
||||||
// Check for a new interface and get info
|
// Check for a new interface and get info
|
||||||
net->checkNewInterface(ifi);
|
net->checkNewInterface(ifi);
|
||||||
|
} else {
|
||||||
|
net->dp.emit();
|
||||||
}
|
}
|
||||||
net->dp.emit();
|
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
} else if (nh->nlmsg_type == RTM_NEWLINK || nh->nlmsg_type == RTM_DELLINK) {
|
} else if (nh->nlmsg_type == RTM_NEWLINK || nh->nlmsg_type == RTM_DELLINK) {
|
||||||
char ifname[IF_NAMESIZE];
|
char ifname[IF_NAMESIZE];
|
||||||
if_indextoname(ifi->ifi_index, ifname);
|
if_indextoname(ifi->ifi_index, ifname);
|
||||||
// Check for valid interface
|
// Check for valid interface
|
||||||
if ((net->ifid_ == -1 || ifi->ifi_index != net->ifid_) && net->checkInterface(ifi, ifname)) {
|
if (ifi->ifi_index != net->ifid_ && net->checkInterface(ifi, ifname)) {
|
||||||
net->ifname_ = ifname;
|
net->ifname_ = ifname;
|
||||||
net->ifid_ = ifi->ifi_index;
|
net->ifid_ = ifi->ifi_index;
|
||||||
// Get Iface and WIFI info
|
// Get Iface and WIFI info
|
||||||
net->getInterfaceAddress();
|
net->getInterfaceAddress();
|
||||||
net->thread_timer_.wake_up();
|
net->thread_timer_.wake_up();
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
} else if (ifi->ifi_index == net->ifid_ && (!(ifi->ifi_flags & IFF_RUNNING) ||
|
} else if (ifi->ifi_index == net->ifid_ &&
|
||||||
!(ifi->ifi_flags & IFF_UP) || !net->checkInterface(ifi, ifname))) {
|
(!(ifi->ifi_flags & IFF_RUNNING) || !(ifi->ifi_flags & IFF_UP) ||
|
||||||
|
!net->checkInterface(ifi, ifname))) {
|
||||||
net->clearIface();
|
net->clearIface();
|
||||||
// Check for a new interface and get info
|
// Check for a new interface and get info
|
||||||
net->checkNewInterface(ifi);
|
net->checkNewInterface(ifi);
|
||||||
@ -623,20 +636,13 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
|||||||
char ifname[IF_NAMESIZE];
|
char ifname[IF_NAMESIZE];
|
||||||
if_indextoname(ifi->ifi_index, ifname);
|
if_indextoname(ifi->ifi_index, ifname);
|
||||||
// Auto detected network can also be assigned here
|
// Auto detected network can also be assigned here
|
||||||
if (net->ifid_ == -1 || ifi->ifi_index != net->ifid_) {
|
if (ifi->ifi_index != net->ifid_ && net->checkInterface(ifi, ifname)) {
|
||||||
// checkInterface may need some delay to detect external interface
|
// If iface is different, clear data
|
||||||
for (uint8_t tries = 0; tries < MAX_RETRY; tries += 1) {
|
if (ifi->ifi_index != net->ifid_) {
|
||||||
if (net->checkInterface(ifi, ifname)) {
|
net->clearIface();
|
||||||
// If iface is different, clear data
|
|
||||||
if (ifi->ifi_index != net->ifid_) {
|
|
||||||
net->clearIface();
|
|
||||||
}
|
|
||||||
net->ifname_ = ifname;
|
|
||||||
net->ifid_ = ifi->ifi_index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
||||||
}
|
}
|
||||||
|
net->ifname_ = ifname;
|
||||||
|
net->ifid_ = ifi->ifi_index;
|
||||||
}
|
}
|
||||||
// Check for valid interface
|
// Check for valid interface
|
||||||
if (ifi->ifi_index == net->ifid_) {
|
if (ifi->ifi_index == net->ifid_) {
|
||||||
|
Loading…
Reference in New Issue
Block a user