From 9046975a81cae3be0896bacceb84dc671e07f23c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Apr 2022 13:04:27 +0200 Subject: [PATCH 1/2] settings: fix assertion failure in NMSettings' _startup_complete_check() This probably has no bad effects when building without more-asserts. #0 __pthread_kill_implementation (threadid=, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 #1 0x00007f7ead0564a3 in __pthread_kill_internal (signo=6, threadid=) at pthread_kill.c:78 #2 0x00007f7ead009d06 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 #3 0x00007f7eacfdc7d3 in __GI_abort () at abort.c:79 #4 0x00007f7ead1fed4c in g_assertion_message (domain=, file=, line=, func=, message=) at ../glib/gtestutils.c:3065 #5 0x00007f7ead25f98f in g_assertion_message_expr (domain=0x560964f8b7e9 "nm", file=0x560964f83da8 "src/core/settings/nm-settings.c", line=640, func=0x56096504a390 <__func__.44.lto_priv.1> "_startup_complete_check", expr=) at ../glib/gtestutils.c:3091 #6 0x0000560964ed710e in _startup_complete_check (self=0x560966d1d030, now_msec=) at src/core/settings/nm-settings.c:640 #7 0x0000560964ed7d9b in _startup_complete_notify_connection (self=0x560966d1d030, sett_conn=, forget=) at src/core/settings/nm-settings.c:704 #8 0x0000560964edd070 in _connection_changed_delete (self=0x560966d1d030, storage=, sett_conn=0x560966cedbc0, allow_add_to_no_auto_default=) at src/core/settings/nm-settings.c:1244 #9 0x0000560964edd948 in _connection_changed_process_one (update_reason=(NM_SETTINGS_CONNECTION_UPDATE_REASON_IGNORE_PERSIST_FAILURE | NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET | unknown: 0x5400), override_sett_flags=0, sett_mask=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, sett_flags=1725440360, allow_add_to_no_auto_default=0, sett_conn_entry=0x560966d1d030, self=) at src/core/settings/nm-settings.c:1294 #10 _connection_changed_process_all_dirty (self=, allow_add_to_no_auto_default=, sett_flags=, sett_mask=, override_sett_flags=, update_reason=) at src/core/settings/nm-settings.c:1335 #11 0x0000560964eeb8ec in nm_settings_delete_connection (allow_add_to_no_auto_default=648659760, sett_conn=, self=0x560966d1d030) at src/core/settings/nm-settings.c:2457 #12 nm_settings_connection_delete (self=, allow_add_to_no_auto_default=648659760) at src/core/settings/nm-settings-connection.c:637 #13 0x0000560964eebebd in delete_auth_cb (self=0x560966cedbc0, context=0x7f7e9c0170a0, subject=0x560966cc5ed0, error=0x0, data=) at src/core/settings/nm-settings-connection.c:1877 #14 0x0000560964ec9778 in pk_auth_cb (auth_manager=, auth_call_id=, is_authorized=1, is_challenge=, auth_error=, user_data=0x560966e16980) at src/core/settings/nm-settings-connection.c:1262 #15 0x0000560964db9a28 in _call_id_invoke_callback (error=0x0, is_challenge=0, is_authorized=1, call_id=0x560966ddeb00) at src/core/nm-auth-manager.c:180 #16 _call_on_idle (user_data=user_data@entry=0x560966ddeb00) at src/core/nm-auth-manager.c:284 #17 0x00007f7ead23111b in g_idle_dispatch (source=0x560966e50190, callback=0x560964db9900 <_call_on_idle>, user_data=0x560966ddeb00) at ../glib/gmain.c:5848 #18 0x00007f7ead234d4f in g_main_dispatch (context=0x560966cd1e20) at ../glib/gmain.c:3337 #19 g_main_context_dispatch (context=0x560966cd1e20) at ../glib/gmain.c:4055 #20 0x00007f7ead289608 in g_main_context_iterate.constprop.0 (context=0x560966cd1e20, block=block@entry=1, dispatch=dispatch@entry=1, self=) at ../glib/gmain.c:4131 #21 0x00007f7ead234463 in g_main_loop_run (loop=0x560966caf010) at ../glib/gmain.c:4329 #22 0x0000560964cb7515 in main (argc=, argv=) at src/core/main.c:509 Fixes: 3df662f534c4 ('settings: rework wait-device-timeout handling and consider device compatibility') --- src/core/settings/nm-settings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index 4a27f1ef6b..1ff66e25de 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -567,6 +567,8 @@ _startup_complete_check(NMSettings *self, gint64 now_msec) return; } + nm_clear_g_source(&priv->startup_complete_timeout_id); + if (c_list_is_empty(&priv->startup_complete_scd_lst_head)) goto ready; @@ -602,8 +604,6 @@ next_with_ready: } c_list_splice(&priv->startup_complete_scd_lst_head, &ready_lst); - nm_clear_g_source(&priv->startup_complete_timeout_id); - if (scd_not_ready) { gint64 timeout_msec; From b2a4d706f8b8239b5770aba07dc9254a37fd2789 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Apr 2022 13:11:36 +0200 Subject: [PATCH 2/2] settings: use GSource instead of numeric ID in NMSettings I find it better style to use GSource pointers for tracking pending sources. --- src/core/settings/nm-settings.c | 53 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/core/settings/nm-settings.c b/src/core/settings/nm-settings.c index 1ff66e25de..2b988527e9 100644 --- a/src/core/settings/nm-settings.c +++ b/src/core/settings/nm-settings.c @@ -389,15 +389,15 @@ typedef struct { gint64 startup_complete_start_timestamp_msec; GHashTable *startup_complete_idx; CList startup_complete_scd_lst_head; - guint startup_complete_timeout_id; + GSource *startup_complete_timeout_source; + + GSource *kf_db_flush_idle_source_timestamps; + GSource *kf_db_flush_idle_source_seen_bssids; guint connections_len; guint connections_generation; - guint kf_db_flush_idle_id_timestamps; - guint kf_db_flush_idle_id_seen_bssids; - bool kf_db_pruned_timestamps; bool kf_db_pruned_seen_bssid; @@ -541,9 +541,9 @@ _startup_complete_timeout_cb(gpointer user_data) NMSettings *self = user_data; NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); - priv->startup_complete_timeout_id = 0; + nm_clear_g_source_inst(&priv->startup_complete_timeout_source); _startup_complete_check(self, 0); - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } static void @@ -567,7 +567,7 @@ _startup_complete_check(NMSettings *self, gint64 now_msec) return; } - nm_clear_g_source(&priv->startup_complete_timeout_id); + nm_clear_g_source_inst(&priv->startup_complete_timeout_source); if (c_list_is_empty(&priv->startup_complete_scd_lst_head)) goto ready; @@ -609,8 +609,10 @@ next_with_ready: timeout_msec = priv->startup_complete_start_timestamp_msec + scd_not_ready->timeout_msec - nm_utils_get_monotonic_timestamp_msec(); - priv->startup_complete_timeout_id = - g_timeout_add(NM_CLAMP(0, timeout_msec, 60000), _startup_complete_timeout_cb, self); + priv->startup_complete_timeout_source = + nm_g_timeout_add_source(NM_CLAMP(0, timeout_msec, 60000), + _startup_complete_timeout_cb, + self); _LOGT("startup-complete: wait for suitable device for connection \"%s\" (%s) which has " "\"connection.wait-device-timeout\" set", nm_settings_connection_get_id(scd_not_ready->sett_conn), @@ -637,7 +639,7 @@ ready: _LOGT("startup-complete: ready, no more profiles to wait for"); priv->startup_complete_start_timestamp_msec = 0; nm_assert(!priv->startup_complete_idx); - nm_assert(priv->startup_complete_timeout_id == 0); + nm_assert(!priv->startup_complete_timeout_source); _notify(self, PROP_STARTUP_COMPLETE); } @@ -3842,13 +3844,13 @@ _kf_db_got_dirty_flush(NMSettings *self, gboolean is_timestamps) NMKeyFileDB *kf_db; if (is_timestamps) { - prefix = "timestamps"; - kf_db = priv->kf_db_timestamps; - priv->kf_db_flush_idle_id_timestamps = 0; + prefix = "timestamps"; + kf_db = priv->kf_db_timestamps; + nm_clear_g_source_inst(&priv->kf_db_flush_idle_source_timestamps); } else { - prefix = "seen-bssids"; - kf_db = priv->kf_db_seen_bssids; - priv->kf_db_flush_idle_id_seen_bssids = 0; + prefix = "seen-bssids"; + kf_db = priv->kf_db_seen_bssids; + nm_clear_g_source_inst(&priv->kf_db_flush_idle_source_seen_bssids); } if (nm_key_file_db_is_dirty(kf_db)) @@ -3859,7 +3861,7 @@ _kf_db_got_dirty_flush(NMSettings *self, gboolean is_timestamps) nm_key_file_db_get_filename(kf_db)); } - return G_SOURCE_REMOVE; + return G_SOURCE_CONTINUE; } static gboolean @@ -3880,26 +3882,27 @@ _kf_db_got_dirty_fcn(NMKeyFileDB *kf_db, gpointer user_data) NMSettings *self = user_data; NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self); GSourceFunc idle_func; - guint *p_id; + GSource **p_source; const char *prefix; if (priv->kf_db_timestamps == kf_db) { prefix = "timestamps"; - p_id = &priv->kf_db_flush_idle_id_timestamps; + p_source = &priv->kf_db_flush_idle_source_timestamps; idle_func = _kf_db_got_dirty_flush_timestamps_cb; } else if (priv->kf_db_seen_bssids == kf_db) { prefix = "seen-bssids"; - p_id = &priv->kf_db_flush_idle_id_seen_bssids; + p_source = &priv->kf_db_flush_idle_source_seen_bssids; idle_func = _kf_db_got_dirty_flush_seen_bssids_cb; } else { nm_assert_not_reached(); return; } - if (*p_id != 0) + if (*p_source) return; _LOGT("[%s-keyfile]: schedule flushing changes to disk", prefix); - *p_id = g_idle_add_full(G_PRIORITY_LOW, idle_func, self, NULL); + *p_source = + nm_g_source_attach(nm_g_idle_source_new(G_PRIORITY_LOW, idle_func, self, NULL), NULL); } void @@ -4100,7 +4103,7 @@ dispose(GObject *object) nm_assert(c_list_is_empty(&priv->sce_dirty_lst_head)); nm_assert(g_hash_table_size(priv->sce_idx) == 0); - nm_clear_g_source(&priv->startup_complete_timeout_id); + nm_clear_g_source_inst(&priv->startup_complete_timeout_source); nm_clear_pointer(&priv->startup_complete_idx, g_hash_table_destroy); nm_assert(c_list_is_empty(&priv->startup_complete_scd_lst_head)); @@ -4154,8 +4157,8 @@ finalize(GObject *object) g_clear_object(&priv->agent_mgr); - nm_clear_g_source(&priv->kf_db_flush_idle_id_timestamps); - nm_clear_g_source(&priv->kf_db_flush_idle_id_seen_bssids); + nm_clear_g_source_inst(&priv->kf_db_flush_idle_source_timestamps); + nm_clear_g_source_inst(&priv->kf_db_flush_idle_source_seen_bssids); _kf_db_to_file(self, TRUE, FALSE); _kf_db_to_file(self, FALSE, FALSE); nm_key_file_db_destroy(priv->kf_db_timestamps);