Skip to content

gh-77043: Make os.dup2(fd, fd) a no-op for valid fd - #5713

Open
izbyshev wants to merge 3 commits into
python:mainfrom
izbyshev:bpo-32862
Open

izbyshev wants to merge 3 commits into
python:mainfrom
izbyshev:bpo-32862

Conversation

@izbyshev

@izbyshev izbyshev commented Feb 17, 2018 •

Copy link
Copy Markdown
Contributor

os.dup2(fd, fd, inheritable=True) never changed fd inheritability,
but with inheritable=False the function might fail or change it
in an inconsistent manner depending on the platform.

https://bugs.python.org/issue32862

os.dup2(fd, fd, inheritable=True) never changed fd inheritability,
but with inheritable=False the function might fail or change it
in an inconsistent manner depending on the platform.
Comment thread Lib/test/test_os.py
# dup2(fd, fd) must have no effect for a valid fd
# Issue #26935: Avoid failure due to a bionic bug
# in old Android.
if (not hasattr(sys, 'getandroidapilevel') or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new test code should be placed in a new method. The Android checks should be put in a @unittest.skip* decorator.

Comment thread Doc/library/os.rst
<fd_inheritance>` by default or non-inheritable if *inheritable*
is ``False``.

If *fd* is valid and equal to *fd2*, this function has no effect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a versionchanged directive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"this function has no effect": that's wrong, it does validate the FD which is a legit usage of this function. I would rather remove this sentence.

Comment thread Lib/test/test_os.py
self.assertFalse(os.get_inheritable(fd3))

# dup2(fd, fd) must have no effect for a valid fd
# Issue #26935: Avoid failure due to a bionic bug

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Issue #26935: Avoid failure due to a bionic bug
# bpo-26935: Avoid failure due to a bionic bug

I believe it's preferred to use bpo-n in code comments.

Comment thread Doc/library/os.rst
<fd_inheritance>` by default or non-inheritable if *inheritable*
is ``False``.

If *fd* is valid and equal to *fd2*, this function has no effect

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"this function has no effect": that's wrong, it does validate the FD which is a legit usage of this function. I would rather remove this sentence.

Comment thread Lib/test/test_os.py
self.assertEqual(os.dup2(fd, fd3, inheritable=False), fd3)
self.assertFalse(os.get_inheritable(fd3))

# dup2(fd, fd) must have no effect for a valid fd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this test into a separated method and emit somehow a SkipTest exception to record that the test is skipped on old Android versions.

Comment thread Modules/posixmodule.c
@@ -8041,7 +8041,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
res = fd2; // msvcrt dup2 returns 0 on success.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document somewhere the rationale for "fd != fd2" tests with a reference to "bpo-32862".

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 15, 2022
@arhadthedev

Copy link
Copy Markdown
Member

Last time this PR was modified five years ago and still has unresolved reviews. If it stays abandoned, it will be closed.

@arhadthedev arhadthedev added the pending The issue will be closed if no feedback is provided label Feb 5, 2023
@izbyshev

Copy link
Copy Markdown
Contributor Author

I'm going to rebase this PR and address the review within a week, please don't close.

@arhadthedev arhadthedev removed the pending The issue will be closed if no feedback is provided label Feb 12, 2023
@izbyshev

Copy link
Copy Markdown
Contributor Author

After revisiting this issue I've come to think that the approach taken in this PR may be not the best. I've created an alternative PR #102148.

I intend to keep this PR open until the discussion in issue #77043 comes to a conclusion.

@arhadthedev arhadthedev added the extension-modules C modules in the Modules dir label Feb 22, 2023
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 6, 2023
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 16, 2024
@serhiy-storchaka serhiy-storchaka changed the title bpo-32862: Make os.dup2(fd, fd) a no-op for valid fd gh-77043: Make os.dup2(fd, fd) a no-op for valid fd Aug 12, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes extension-modules C modules in the Modules dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants