GIO NetworkMonitor doesn't reflect the current network state
System: Arch Linux + Cinnamon + Network Manager GLib version: 2.58.0-1
Take the following code:
#include <gio/gio.h>
#include <iostream>
int main ()
{
GNetworkMonitor* monitor = g_network_monitor_get_default();
std::cout << std::boolalpha << static_cast<bool>(g_network_monitor_get_network_available(monitor)) << std::endl;
std::cout << g_network_monitor_get_connectivity(monitor) << std::endl;
return 0;
}
Compiled with
g++ $(pkg-config --libs --cflags gio-2.0) main.cpp -o main
Then the result of this program is always
true
4
no matter if the WLAN connection (the only active connection) is turned on or off via the Cinnamon Network Manager applet. ip a
confirms that the connection gets down.
Similarly, this Python code:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk
def network_status_changed(monitor, connected):
print(f"xD {connected}")
network_monitor = Gio.NetworkMonitor.get_default()
network_monitor.connect('network-changed', network_status_changed)
print(network_monitor.get_connectivity())
Gtk.main()
always shows G_NETWORK_CONNECTIVITY_FULL
and never executes the callback for the network-changed
signal.
There are three interfaces in the system: lo
, enpXsY
(always down) and wlpXsY
(down or up, depending on the case)
journalctl-xe
shows no relevant errors
Edited by Marcin Mielniczuk