gmessages: Error if g_log_set_writer_func() is called multiple times

Inspired by https://gitlab.gnome.org/GNOME/glib/-/issues/2638.

This requires moving the tests to subprocesses, so that
`g_log_set_writer_func()` is only called once per process.

It also adds a test for the new error.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall
2022-04-25 12:23:45 +01:00
parent cc99d6ee97
commit dfb3517d37
2 changed files with 216 additions and 109 deletions

View File

@@ -2059,9 +2059,18 @@ g_log_set_writer_func (GLogWriterFunc func,
g_return_if_fail (func != NULL);
g_mutex_lock (&g_messages_lock);
if (log_writer_func != g_log_writer_default)
{
g_mutex_unlock (&g_messages_lock);
g_error ("g_log_set_writer_func() called multiple times");
return;
}
log_writer_func = func;
log_writer_user_data = user_data;
log_writer_user_data_free = user_data_free;
g_mutex_unlock (&g_messages_lock);
}