Message351461
> That's very unlikely to happen. I believe it was added as an opt-in feature for some linux compatibility situations. The correct solution is to use closefrom(2), as it is the optimal current solution, and in our case, safe to use.
If you have like 50k open file descriptors and want to pass fd 50000 to a child process using Popen(pass_fds={50000}), you will have to call close() 49 997 times: close(3)..close(49999), then closefrom(50001).
For the pass_fds case, being able to enumerate open file descriptors (ex: fdescfs) is more efficient than closefrom().
Well, the best would be a system call "close all file descriptors except of <list of fds>", but it's not available yet. Or maybe at least having a system like close_range(a, b).
In May 2019, the close_range() syscall was in the Linux kernel !
https://lwn.net/Articles/789023/
... but it seems like the feature was not accepted yet.
I'm disappointed that posix_spawn() doesn't implement a feature like Python subprocess close_fds=True. |
|
Date |
User |
Action |
Args |
2019-09-09 13:36:56 | vstinner | set | recipients:
+ vstinner, koobs |
2019-09-09 13:36:56 | vstinner | set | messageid: <1568036216.79.0.0154697404509.issue38061@roundup.psfhosted.org> |
2019-09-09 13:36:56 | vstinner | link | issue38061 messages |
2019-09-09 13:36:56 | vstinner | create | |
|