From ab1dee5bdb9089399b2000880eaa8f702a846f89 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sun, 1 Nov 2026 18:17:27 +0300 Subject: [PATCH] Close the spawned child's descriptors only where glibc has posix_spawn_file_actions_addclosefrom_np The Linux release builds against the Steam Runtime's glibc 2.31, which lacks that 2.34 call: plat_restart and plat_spawn stopped the runtime library from compiling. A weak reference uses it when the running glibc has it. Co-Authored-By: Claude Opus 5.5 --- runtime/platform/linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/platform/linux.c b/runtime/platform/linux.c index 631660a1..7d502925 100644 --- a/runtime/platform/linux.c +++ b/runtime/platform/linux.c @@ -1679,6 +1679,14 @@ static unsigned long long process_start(int pid) { return start; } +// glibc 2.34 added posix_spawn_file_actions_addclosefrom_np, and the release links against the Steam Runtime's 2.31: a +// weak reference, used when the running glibc has it. Without it the child inherits the open descriptors. +extern int posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *fa, int from) __attribute__((weak)); + +static void spawn_close_from(posix_spawn_file_actions_t *fa, int from) { + if (posix_spawn_file_actions_addclosefrom_np) posix_spawn_file_actions_addclosefrom_np(fa, from); +} + int plat_restart(void) { // the arguments, NUL-separated, from /proc/self/cmdline static char args[16384]; @@ -1695,7 +1703,7 @@ int plat_restart(void) { snprintf(wait, sizeof wait, "%d.%llu", (int)getpid(), process_start((int)getpid())); posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); - posix_spawn_file_actions_addclosefrom_np(&fa, 3); + spawn_close_from(&fa, 3); posix_spawnattr_t at; posix_spawnattr_init(&at); sigset_t none, all; @@ -1716,7 +1724,7 @@ int plat_restart(void) { int plat_spawn(const char *const *argv, const char *cwd) { posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); - posix_spawn_file_actions_addclosefrom_np(&fa, 3); + spawn_close_from(&fa, 3); posix_spawn_file_actions_addchdir_np(&fa, cwd); posix_spawnattr_t at; posix_spawnattr_init(&at);