Skip to content

gspawn: Fix g_spawn deadlock in a multi-threaded program on Linux

opendir and closedir are not async-signal-safe, these may call malloc under the hood and cause a deadlock in a multi-threaded program. This only affected Linux when /proc is mounted, other systems use a slower path that iterates through all potential file descriptors. Fixes a long-standing problem (since GLib 2.14.2).

Closes #945 (closed) and #1014 (closed)


Note that default glibc seems to use a 32K buffer (as observed via strace), here I chose for a 4K buffer instead (the getdents64 manual example has 1K) as the entries are not expected to be large (filenames are numbers).

Merge request reports