This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PEP446 (CLOEXEC by default) violation with fcntl.fcntl(..., fcntl.F_DUPFD)
Type: behavior Stage:
Components: Documentation, Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, martin.panter, socketpair, vstinner
Priority: normal Keywords:

Created on 2016-05-29 07:34 by socketpair, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg266591 - (view) Author: Марк Коренберг (socketpair) * Date: 2016-05-29 07:34
1. Need fix the code
2. Fix documentation
3. Update PEP446 description.

There is F_DUPFD_CLOEXEC constant, that must be used instead of F_DUPFD transparently when kernel >= 2.6.24.
msg266592 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-29 08:10
I don’t see any violation or anything needing fixing in the documentation or code. Can you elaborate?

The fcntl() documentation says “The values used for ‘cmd’ [F_DUPFD, etc] are operating system dependent, and are available as constants in the ‘fcntl’ module, using the same names as used in the relevant C header files.” The newest version of Posix specifies both the F_DUPFD and F_DUPFD_CLOEXEC. It would be misleading for Python to use one when the user specified the other.

If you want a best-effort version of F_DUPFD_CLOEXEC for a single-threaded program, why not use os.dup()? I presume this uses F_DUPFD_CLOEXEC where appropriate, and uses some non-atomic fallback if necessary.
msg266595 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-05-29 09:11
I don't think that it's possible nor worth it to wrap all fcntl() and all
ioctl() calls. I see these functions as very low-level APIs and so I
consider that the caller is responsible of what he/she does.

If you want to change something, explian in fcntl module doc that the PEP
466 is not implemented in this module znd it's a deliberate choice.

I agree with Martin, it's the responsability of the dev to use the right
command depending on the use case.
msg266610 - (view) Author: Марк Коренберг (socketpair) * Date: 2016-05-29 18:26
OK, it will be consistent, if docs mention that F_DUPFD will not set O_CLOEXEC automatically, mentiont that F_DUPFD_CLOEXEC should be used for that, and also mention PEP446 somewhere.
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71337
2016-05-29 18:26:37socketpairsetmessages: + msg266610
2016-05-29 09:11:49vstinnersetmessages: + msg266595
2016-05-29 08:10:27martin.pantersetnosy: + vstinner, martin.panter
messages: + msg266592
2016-05-29 07:35:42socketpairsetversions: + Python 3.4, Python 3.5, Python 3.6
nosy: + docs@python

assignee: docs@python
components: + Documentation, Library (Lib)
type: behavior
2016-05-29 07:34:25socketpaircreate