Marco Trevisan (Treviño) 5fd0825958 gio/subprocess: Lock while writing on shared pid and status values
The process PID is initialized by the initable vfunc, while
g_subprocess_exited sets it again, when we're protecting it via a lock.
The status is set when the process exits instead, again while locking.

This makes the thread sanitizer unhappy (even if it shouldn't really be
a race for the PID init case), but still locking during initialization is
not a bad thing to do.

At the same time g_subprocess_wait() and friends were using the pid and status
values without any protection, so let's ensure this is not the case anymore.

WARNING: ThreadSanitizer: data race (pid=8213)
  Write of size 4 at 0x7b200000084c by thread T1:
    #0 g_subprocess_exited ../gio/gsubprocess.c:284
    #1 g_child_watch_dispatch ../glib/gmain.c:5963
    #2 g_main_dispatch ../glib/gmain.c:3373
    #3 g_main_context_dispatch_unlocked ../glib/gmain.c:4224
    #4 g_main_context_iterate_unlocked ../glib/gmain.c:4289
    #5 g_main_context_iteration ../glib/gmain.c:4354
    #6 glib_worker_main ../glib/gmain.c:6553
    #7 g_thread_proxy ../glib/gthread.c:892
  Previous read of size 4 at 0x7b200000084c by main thread:
    #0 g_subprocess_wait ../gio/gsubprocess.c:908
    #1 g_subprocess_wait_check ../gio/gsubprocess.c:939
    #2 end_element ../gio/glib-compile-resources.c:342
    #3 emit_end_element ../glib/gmarkup.c:1045
    #4 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #5 parse_resource_file ../gio/glib-compile-resources.c:578
    #6 main ../gio/glib-compile-resources.c:967
  Location is heap block of size 120 at 0x7b2000000800 allocated by main
  thread:
    #0 calloc <null>
    #1 g_malloc0 ../glib/gmem.c:133
    #2 g_type_create_instance ../gobject/gtype.c:1933
    #3 g_object_new_internal ../gobject/gobject.c:2621
    #4 g_object_new_valist ../gobject/gobject.c:2960
    #5 g_initable_new_valist ../gio/ginitable.c:245
    #6 g_initable_new ../gio/ginitable.c:163
    #7 g_subprocess_newv ../gio/gsubprocess.c:619
    #8 g_subprocess_new ../gio/gsubprocess.c:590
    #9 end_element ../gio/glib-compile-resources.c:334
    #10 emit_end_element ../glib/gmarkup.c:1045
    #11 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #12 parse_resource_file ../gio/glib-compile-resources.c:578
    #13 main ../gio/glib-compile-resources.c:967
  Thread T1 'gmain' (tid=8228, running) created by main thread at:
    #0 pthread_create <null>
    #1 g_system_thread_new ../glib/gthread-posix.c:762
    #2 g_thread_new_internal ../glib/gthread.c:996
    #3 g_thread_new ../glib/gthread.c:949
    #4 g_get_worker_context ../glib/gmain.c:6580
    #5 initable_init ../gio/gsubprocess.c:443
    #6 g_initable_init ../gio/ginitable.c:129
    #7 g_initable_new_valist ../gio/ginitable.c:249
    #8 g_initable_new ../gio/ginitable.c:163
    #9 g_subprocess_newv ../gio/gsubprocess.c:619
    #10 g_subprocess_new ../gio/gsubprocess.c:590
    #11 end_element ../gio/glib-compile-resources.c:334
    #12 emit_end_element ../glib/gmarkup.c:1045
    #13 g_markup_parse_context_parse ../glib/gmarkup.c:1603
    #14 parse_resource_file ../gio/glib-compile-resources.c:578
    #15 main ../gio/glib-compile-resources.c:967
SUMMARY: ThreadSanitizer: data race ../gio/gsubprocess.c:284 in
g_subprocess_exited

======================================

WARNING: ThreadSanitizer: data race (pid=15959)
  Read of size 4 at 0x7b200000084c by main thread:
    #0 g_subprocess_wait ../gio/gsubprocess.c:913
    #1 g_subprocess_wait_check ../gio/gsubprocess.c:944
    #2 test_cat_utf8 ../gio/tests/gsubprocess.c:489
    #3 test_case_run ../glib/gtestutils.c:3115
    #4 g_test_run_suite_internal ../glib/gtestutils.c:3210
    #5 g_test_run_suite_internal ../glib/gtestutils.c:3229
    #6 g_test_run_suite ../glib/gtestutils.c:3310
    #7 g_test_run ../glib/gtestutils.c:2379
    #8 main ../gio/tests/gsubprocess.c:2266

  Previous write of size 4 at 0x7b200000084c by thread T1:
    #0 g_subprocess_exited ../gio/gsubprocess.c:284
    #1 g_child_watch_dispatch ../glib/gmain.c:5963
    #2 g_main_dispatch ../glib/gmain.c:3373
    #3 g_main_context_dispatch_unlocked ../glib/gmain.c:4224
    #4 g_main_context_iterate_unlocked ../glib/gmain.c:4289
    #5 g_main_context_iteration ../glib/gmain.c:4354
    #6 glib_worker_main ../glib/gmain.c:6553
    #7 g_thread_proxy ../glib/gthread.c:892
2025-02-11 15:22:19 +01:00
2024-04-01 11:01:06 +00:00
2023-07-30 17:03:07 +04:00
2024-09-12 22:23:46 +00:00
2019-11-21 14:03:01 -06:00
2021-10-28 14:47:53 +01:00
2024-10-18 14:59:20 +08:00
2025-01-23 13:20:40 +00:00
2024-08-29 08:58:36 +01:00

GLib

GLib is the low-level core library that forms the basis for projects such as GTK and GNOME. It provides data structure handling for C, portability wrappers, and interfaces for such runtime functionality as an event loop, threads, dynamic loading, and an object system.

The official download locations are: https://download.gnome.org/sources/glib

The official web site is: https://www.gtk.org/

Installation

See the file INSTALL.md. There is separate and more in-depth documentation for building GLib on Windows.

Supported versions

Upstream GLib only supports the most recent stable release series, the previous stable release series, and the current development release series. All older versions are not supported upstream and may contain bugs, some of which may be exploitable security vulnerabilities.

See SECURITY.md for more details.

Documentation

API documentation is available online for GLib for the:

Discussion

If you have a question about how to use GLib, seek help on GNOMEs Discourse instance. Alternatively, ask a question on StackOverflow and tag it glib.

Reporting bugs

Bugs should be reported to the GNOME issue tracking system. You will need to create an account for yourself. You may also submit bugs by e-mail (without an account) by e-mailing incoming+gnome-glib-658-issue-@gitlab.gnome.org, but this will give you a degraded experience.

Bugs are for reporting problems in GLib itself, not for asking questions about how to use it. To ask questions, use one of our discussion forums.

In bug reports please include:

  • Information about your system. For instance:
    • What operating system and version
    • For Linux, what version of the C library
    • And anything else you think is relevant.
  • How to reproduce the bug.
    • If you can reproduce it with one of the test programs that are built in the tests/ subdirectory, that will be most convenient. Otherwise, please include a short test program that exhibits the behavior. As a last resort, you can also provide a pointer to a larger piece of software that can be downloaded.
  • If the bug was a crash, the exact text that was printed out when the crash occurred.
  • Further information such as stack traces may be useful, but is not necessary.

Contributing to GLib

Please follow the contribution guide to know how to start contributing to GLib.

Patches should be submitted as merge requests to gitlab.gnome.org. Note that you will need to be logged in to the site to use this page. If the patch fixes an existing issue, please refer to the issue in your commit message with the following notation (for issue 123):

Closes: #123

Otherwise, create a new merge request that introduces the change. Filing a separate issue is not required.

Description
Low-level core library that forms the basis for projects such as GTK+ and GNOME.
Readme 115 MiB
Languages
C 95.3%
Python 2.3%
Meson 1.3%
Objective-C 0.3%
Shell 0.2%
Other 0.5%