Re: [PATCH] O_CLOEXEC not honored on Windows - handle inheritance chain
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Bryan Green <dbryan.green@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-12-13T02:44:11Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
ci: Test Windows + Mkvcbuild.pm in REL_16_STABLE.
- 4b9ce1ef609b 16.12 landed
-
Fix Mkvcbuild.pm builds of test_cloexec.c.
- 4da5c33a3a04 18.2 landed
- 45d92b76dc4a 19 (unreleased) landed
- 80e8ec772bff 16.12 landed
- b3c8119e28c0 17.8 landed
-
Clean up test_cloexec.c and Makefile.
- 0666ccc16cc2 16.12 landed
- 0451859131e5 17.8 landed
- a7d06e74d512 18.2 landed
- bec2a0aa3065 19 (unreleased) landed
-
Fix O_CLOEXEC flag handling in Windows port.
- d62a258cd45a 16.12 landed
- f24af0e04cef 17.8 landed
- bebb281b08b6 18.2 landed
- c507ba55f5bf 19 (unreleased) landed
-
Don't leak descriptors into subprograms.
- 1da569ca1f1f 16.0 cited
Thomas Munro <thomas.munro@gmail.com> writes:
> Hearing nothing, pushed.
fairywren is unimpressed:
../pgsql/src/test/modules/test_cloexec/test_cloexec.c: In function 'run_parent_tests':
../pgsql/src/test/modules/test_cloexec/test_cloexec.c:137:29: warning: unused variable 'space_pos' [-Wunused-variable]
137 | char *space_pos;
| ^~~~~~~~~
It's right, but it seems to me that this stanza needs more help than
that:
/*
* Spawn child process with bInheritHandles=TRUE, passing handle values as
* hex strings
*/
snprintf(cmdline, sizeof(cmdline), "\"%s\" %p %p",
GetCommandLine(), h1, h2);
/*
* Find the actual executable path by removing any arguments from
* GetCommandLine().
*/
{
char exe_path[MAX_PATH];
char *space_pos;
GetModuleFileName(NULL, exe_path, sizeof(exe_path));
snprintf(cmdline, sizeof(cmdline), "\"%s\" %p %p",
exe_path, h1, h2);
}
What is the point of that first snprintf(cmdline, ...), when its
result is guaranteed to be overwritten just below?
I'm also dubious about using MAX_PATH here; see the commentary
about MAXPGPATH in pg_config_manual.h. Also, what's the point of
using MAX_PATH when the result is going to be transferred into
cmdline (with a hardwired size of 1024)?
regards, tom lane