@samitouri / QOSamiQemu / commits / 09218537e4

tests/qtest/dbus-vmstate: Mute Glib complaints about g_unsetenv thread-safety

TLDR: GLib is bugged, the dbus-vmstate-test spams debug messages unconditionally. Mute them. GLib is trying to protect against the lack of thread-safety of setenv/unsetsenv functions by warning when those functions were invoked after a thread has been started. https://gitlab.gnome.org/GNOME/glib/issues/715 Unfortunately: 1) GLib itself starts a thread pool via _g_dbus_initialize when working around a bug in its type dependency chain. This happens in many places, but the test triggers it via g_dbus_address_get_for_bus_sync. https://bugzilla.gnome.org/show_bug.cgi?id=627724 2) GLib itself calls g_unsetenv after the test calls g_test_dbus_up. 3) The debug message at g_unsetenv is issued to the G_LOG_DOMAIN defined while compiling the library, i.e "GLib", but this domain is never initialized, so the log functions go into a fallback chain that results in ignoring the G_MESSAGES_DEBUG environment variable, causing the debug messages to not be suppressed when they should. Mute the messages by implementing a handler for G_LOG_LEVEL_DEBUG in the "GLib" log domain and honoring G_MESSAGES_DEBUG. Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260429190550.20122-3-farosas@suse.de>

Fabiano Rosas committed Apr 29, 2026 at 16:05 UTC 09218537e453caf123f4c451e5d3251f1e59ee18
1 file changed +21
tests/qtest/dbus-vmstate-test.c
+21
@@ -357,12 +357,33 @@ test_dbus_vmstate_missing_dst(char *name, MigrateCommon *args)
357 g_test_trap_assert_passed();
358 }
359
360 +static void log_func(const gchar *log_domain, GLogLevelFlags log_level,
361 + const gchar *message, gpointer user_data)
362 +{
363 + const gchar *domains;
364 +
365 + assert(log_level & G_LOG_LEVEL_DEBUG);
366 +
367 + domains = getenv("G_MESSAGES_DEBUG");
368 + if (!domains || (!strstr(domains, "GLib") && !strstr(domains, "all"))) {
369 + return;
370 + }
371 + g_log_default_handler("GLib", G_LOG_LEVEL_DEBUG, message, NULL);
372 +}
373 +
374 int
375 main(int argc, char **argv)
376 {
377 GError *err = NULL;
378 int ret;
379
380 + /*
381 + * GLib currently emits debug messages that ignore
382 + * G_MESSAGES_DEBUG. Set a custom log handler to work around the
383 + * issue.
384 + */
385 + g_log_set_handler("GLib", G_LOG_LEVEL_DEBUG, log_func, NULL);
386 +
387 g_test_init(&argc, &argv, NULL);
388
389 workdir = g_dir_make_tmp("dbus-vmstate-test-XXXXXX", &err);