Author vstinner
Recipients koobs, vstinner
Date 2019-09-09.07:41:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568014873.55.0.858123124378.issue38061@roundup.psfhosted.org>
In-reply-to
Content
> On Linux, _posixsubprocess lists the content of /proc/self/fd/ to only close open file descriptor, after fork() and before exec().

This code is specific to Linux because it uses the SYS_getdents64 syscall.

FreeBSD has a similar concept using /dev/fd "file-descriptor file system". See fdescfs manual page:
https://www.freebsd.org/cgi/man.cgi?query=fdescfs&sektion=5

I'm not sure how it is supposed to work. When I open a file in Python, I don't see its file descriptor in /dev/fd:

vstinner@freebsd$ python3
Python 3.6.9 (default, Aug  8 2019, 01:16:42) 
>>> import os
>>> os.listdir("/dev/fd")
['0', '1', '2']
>>> f=open("/etc/motd")
>>> os.listdir("/dev/fd")
['0', '1', '2']
>>> f.fileno()
3

>>> os.set_inheritable(f.fileno(), True)
>>> os.listdir("/dev/fd")
['0', '1', '2']

>>> import sys, subprocess
>>> rc=subprocess.call([sys.executable, "-c", "import os; print(os.listdir('/dev/fd')); print(os.fstat(3))"], close_fds=False)
['0', '1', '2']
os.stat_result(st_mode=33188, st_ino=321134, st_dev=83, st_nlink=1, st_uid=0, st_gid=0, st_size=899, st_atime=1568014491, st_mtime=1566390614, st_ctime=1566390614)


The file descriptor 3 is not listed in /dev/fd/. It is inherited: fstat(3) in a child process doesn't fail and it's not listed in /dev/fd/ in the child process.
History
Date User Action Args
2019-09-09 07:41:13vstinnersetrecipients: + vstinner, koobs
2019-09-09 07:41:13vstinnersetmessageid: <1568014873.55.0.858123124378.issue38061@roundup.psfhosted.org>
2019-09-09 07:41:13vstinnerlinkissue38061 messages
2019-09-09 07:41:13vstinnercreate