summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2023-01-16 08:10:37 +0100
committerLubomir Rintel <lkundrak@v3.sk>2023-01-25 13:28:19 +0100
commitd21e38041bd05aed52324f2e83d53b238a291b90 (patch)
tree97fc5d18e5057ea1aae232dd8593c8edca8ef011
parenta6bebd700a26b4a82eaac495568831caf38dc5a1 (diff)
libnm/client: don't consider client running if we got no NMManagerlr/client-running
We silently tolerate NetworkManager not responding at all (easily reproduced with e.g. pkill -STOP NetworkManager): $ LIBNM_CLIENT_DEBUG=trace nmcli c show dummy666 libnm-dbus[23540]: <debug> [3316.81989] nmclient[ddafb84b8deebe4a]: new NMClient instance libnm-dbus[23540]: <debug> [3316.81998] nmclient[ddafb84b8deebe4a]: starting async initialization... libnm-dbus[23540]: <debug> [3316.82461] nmclient[ddafb84b8deebe4a]: name owner changed: (null) -> ":1.2" libnm-dbus[23540]: <debug> [3316.82464] nmclient[ddafb84b8deebe4a]: fetch all libnm-dbus[23540]: <debug> [3341.85715] nmclient[ddafb84b8deebe4a]: GetManagedObjects() call failed: Timeout was reached libnm-dbus[23540]: <debug> [3341.85740] nmclient[ddafb84b8deebe4a]: async init complete with success Error: dummy666 - no such connection profile. libnm-dbus[23540]: <debug> [3341.86723] nmclient[ddafb84b8deebe4a]: release all libnm-dbus[23540]: <debug> [3341.86798] nmclient[ddafb84b8deebe4a]: disposed $ As a comment in _dbus_get_managed_objects_cb() explains, this is sort of intentional. NetworkManager might just be shutting down and the libnm users will eventually see the objects once a new daemon starts up. This may make some sense for long-running clients ("nmcli monitor", various desktop environments), but not for one-shot invocations that require the daemon running, such as those of "nmcli c ...". Let's not consider the client running unless we actually got the manager object. That way the error message will make more sense: $ LIBNM_CLIENT_DEBUG=trace nmcli c show dummy666 libnm-dbus[24730]: <debug> [5360.95480] nmclient[8cb898d3c891e210]: new NMClient instance libnm-dbus[24730]: <debug> [5360.95487] nmclient[8cb898d3c891e210]: starting async initialization... libnm-dbus[24730]: <debug> [5360.95901] nmclient[8cb898d3c891e210]: name owner changed: (null) -> ":1.2" libnm-dbus[24730]: <debug> [5360.95904] nmclient[8cb898d3c891e210]: fetch all libnm-dbus[24730]: <debug> [5385.98487] nmclient[8cb898d3c891e210]: GetManagedObjects() call failed: Timeout was reached libnm-dbus[24730]: <debug> [5385.98497] nmclient[8cb898d3c891e210]: async init complete with success Error: NetworkManager is not running. libnm-dbus[24730]: <debug> [5385.98571] nmclient[8cb898d3c891e210]: release all libnm-dbus[24730]: <debug> [5385.98698] nmclient[8cb898d3c891e210]: disposed $ https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1502
-rw-r--r--src/libnm-client-impl/nm-client.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libnm-client-impl/nm-client.c b/src/libnm-client-impl/nm-client.c
index 7441ee25c8..f19343f056 100644
--- a/src/libnm-client-impl/nm-client.c
+++ b/src/libnm-client-impl/nm-client.c
@@ -378,7 +378,7 @@ static void name_owner_changed_cb(GDBusConnection *connection,
static void name_owner_get_call(NMClient *self);
-static void _set_nm_running(NMClient *self);
+static void _set_nm_running(NMClient *self, gboolean queue_notify);
/*****************************************************************************/
@@ -2724,6 +2724,7 @@ _obj_handle_dbus_changes(NMClient *self, NMLDBusObject *dbobj)
if (dbobj->dbus_path == _dbus_path_nm) {
nm_assert(!priv->dbobj_nm);
priv->dbobj_nm = dbobj;
+ _set_nm_running(self, TRUE);
} else if (dbobj->dbus_path == _dbus_path_settings) {
nm_assert(!priv->dbobj_settings);
priv->dbobj_settings = dbobj;
@@ -2783,6 +2784,7 @@ _obj_handle_dbus_changes(NMClient *self, NMLDBusObject *dbobj)
if (dbobj->dbus_path == _dbus_path_nm) {
nm_assert(priv->dbobj_nm == dbobj);
priv->dbobj_nm = NULL;
+ _set_nm_running(self, TRUE);
nml_dbus_property_o_clear_many(priv->nm.property_o,
G_N_ELEMENTS(priv->nm.property_o),
self);
@@ -2936,7 +2938,7 @@ _dbus_handle_changes_commit(NMClient *self, gboolean allow_init_start_check_comp
_nm_client_notify_event_emit(self);
- _set_nm_running(self);
+ _set_nm_running(self, FALSE);
if (allow_init_start_check_complete)
_init_start_check_complete(self);
@@ -4083,15 +4085,18 @@ nm_client_get_startup(NMClient *client)
}
static void
-_set_nm_running(NMClient *self)
+_set_nm_running(NMClient *self, gboolean queue_notify)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE(self);
gboolean nm_running;
- nm_running = priv->name_owner && !priv->get_managed_objects_cancellable;
+ nm_running = priv->dbobj_nm && priv->name_owner && !priv->get_managed_objects_cancellable;
if (priv->nm_running != nm_running) {
priv->nm_running = nm_running;
- _notify(self, PROP_NM_RUNNING);
+ if (queue_notify) {
+ _nm_client_queue_notify_object(self, self, obj_properties[PROP_NM_RUNNING]);
+ } else
+ _notify(self, PROP_NM_RUNNING);
}
}
@@ -7171,7 +7176,7 @@ name_owner_changed(NMClient *self, const char *name_owner)
if (changed && priv->name_owner)
_init_fetch_all(self);
- _set_nm_running(self);
+ _set_nm_running(self, FALSE);
if (priv->init_data) {
nm_auto_pop_gmaincontext GMainContext *main_context = NULL;