In article <21465.1682869...@jacaranda.noi.kre.to>, Robert Elz <k...@munnari.oz.au> wrote: > Date: Sun, 30 Apr 2023 05:25:41 +0000 > From: David Holland <dholland-t...@netbsd.org> > Message-ID: <ze371uhm+zxvn...@netbsd.org> > > | Close-on-fork is apparently either coming or already here, not sure > | which, but it's also per-descriptor. > >We don't have it, but it will be in Posix-8. Largely inspired by the >needs of threaded programs (without lots of critical sections, one cannot >otherwise open anything if another thread might fork, there's no >way to avoid race conditions, hence O_CLOFORK on open ... not sure if >anyone has thought of a way to add it to socket() - that doesn't look >to be trivial, though it might be possible to abuse one of the params >it has - probably domain - and add flags in upper bits ... while having >it able to be set/reset via fcntl is useful, to work, it needs to be >able to be set atomically with the operation that creates the fd, and >having it default "on", which would work, would break almost all existing >non-trivial code).
We already abuse "type": The following flags can be or'ed to the type to condition the returned file descriptor: The following flags are valid: SOCK_CLOEXEC Set the close on exec property. SOCK_NONBLOCK Sets non-blocking I/O. SOCK_NOSIGPIPE Return EPIPE instead of raising SIGPIPE. christos