O_NOSTD
O_NOSTD
Posted Aug 27, 2009 2:54 UTC (Thu) by foom (subscriber, #14868)In reply to: O_NOSTD by pr1268
Parent article: In brief
Indeed. It, O_NOSTD, like O_CLOEXEC before it, are almost entirely pointless extensions that basically only gnu coreutils and glibc can ever use. And when I think of all the functions that needed extra arguments added just to be able to pass the O_CLOEXEC flag...ugh.
IMO, Instead of O_CLOEXEC, glibc should have added a function to close all but a specified list of fds. And apps or libraries could call this themselves after fork, before exec. Obviously you can write this yourself already by iterating over the files in /proc/self/fds, but I just want to write:
int keep_fds[] = {0,1,2,-1}; close_everything_but(keep_fds);
and be done with it! The list of fds to keep across a given call to exec is *always* going to be small, and known to the program calling exec. And then, it's also trivial to write the compatibility library for non-glibc platforms...
Sigh. And now this O_NOSTD...so instead of just calling a single function at program startup, I have to change every open call in every library that I use to use O_NOSTD? Yeah, right.
If they're that concerned about number-of-syscalls-per-program-start, why not just make a single syscall for "make sure I have fds 0,1, and 2 open to a fd, otherwise open /dev/null there". Yay, now I only have a single syscall on program startup. That'd make much more sense than this proposal...