I have to disagree about O_CLOEXEC
I have to disagree about O_CLOEXEC
Posted Nov 26, 2010 22:51 UTC (Fri) by neilbrown (subscriber, #359)In reply to: I have to disagree about O_CLOEXEC by Ross
Parent article: Ghosts of Unix past, part 2: Conflated designs
However 'exec' is very special. Unlike fork and everything else, the calling process has no control over what happens after the exec call succeeds, so it needs to do everything before.
It could close some file descriptors before without racing with other threads by using 'unshare' to have a private file-table, then closing whatever has been marked in libc as 'close on exec'.
But there are (or at least 'could be') times when you want some file descriptor to still be open if 'exec' fails, but you don't want it to be open after the exec succeeds. For that you really need close-on-exec.
And if it is necessary to have clone-on-exec, then it makes most sense for it to default to 'set' as that is commonly what is wanted, and that is easiest to manage in a race-free way.
The main point that I got from your comment is that while is might be clear that something isn't right with this whole design area, it is open for debate which bits are 'right' and which bits are 'wrong'. I would certainly agree with that.