Re: File descriptors in exec'd subprocesses
От | Thomas Munro |
---|---|
Тема | Re: File descriptors in exec'd subprocesses |
Дата | |
Msg-id | CA+hUKGJrgKt17bTxXOQpNcfQ7pOXXeTUxo6Jn6sz+xHXw=ta1g@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: File descriptors in exec'd subprocesses (Andres Freund <andres@anarazel.de>) |
Ответы |
Re: File descriptors in exec'd subprocesses
|
Список | pgsql-hackers |
On Mon, Feb 6, 2023 at 3:29 AM Andres Freund <andres@anarazel.de> wrote: > On February 5, 2023 1:00:50 AM GMT+01:00, Thomas Munro <thomas.munro@gmail.com> wrote: > >Are there any more descriptors we need to think about? > > Postmaster's listen sockets? Saves a bunch of syscalls, at least. Assuming you mean accepted sockets, yeah, I see how two save two syscalls there, and since you nerd-sniped me into looking into the SOCK_CLOEXEC landscape, I like it even more now that I've understood that accept4() is rubber-stamped for the next revision of POSIX[1] and is already accepted almost everywhere. It's not just window dressing, you need it to write multi-threaded programs that fork/exec without worrying about the window between fd creation and fcntl(FD_CLOEXEC) in another thread; hopefully one day we will care about that sort of thing in some places too! Here's a separate patch for that. I *guess* we need HAVE_DECL_ACCEPT4 for the guarded availability system (cf pwritev) when Apple gets the memo, but see below. Hard to say if AIX is still receiving memos (cf recent speculation in the Register). All other target OSes seem to have had this stuff for a while. Since client connections already do fcntl(FD_CLOEXEC), postgres_fdw connections didn't have this problem. It seems reasonable to want to skip a couple of system calls there too; also, client programs might also be interested in future-POSIX's atomic race-free close-on-exec socket fabrication. So here also is a patch to use SOCK_CLOEXEC on that end too, if available. But ... hmph, all we can do here is test for the existence of SOCK_NONBLOCK and SOCK_CLOEXEC, since there is no new function to test for. Maybe we should just assume accept4() also exists if these exist (it's hard to imagine that Apple or IBM would address atomicity on one end but not the other of a socket), but predictions are so difficult, especially about the future! Anyone want to guess if it's better to leave the meson/configure probe in for the accept4 end or just roll with the macros? > Logging collector pipe write end, in backends? The write end of the logging pipe is already closed, after dup2'ing it to STDOUT_FILENO to STDERR_FILENO, so archive commands and suchlike do receive the handle, but they want them. It's the intended and documented behaviour that anything written to that will finish up in the log. As for pipe2(O_CLOEXEC), I see the point of it in a multi-threaded application. It's not terribly useful for us though, because we usually want to close only one end, except in the case of the self-pipe. But the self-pipe is no longer used on the systems that have pipe2()-from-the-future. I haven't tested this under EXEC_BACKEND yet. [1] https://www.austingroupbugs.net/view.php?id=411
Вложения
В списке pgsql-hackers по дате отправления: