Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newly added test_cmd_line_script.test_script_as_dev_fd() fails on FreeBSD: /dev/fd/3 doesn't exist #100005

Closed
vstinner opened this issue Dec 5, 2022 · 1 comment
Labels
type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

vstinner commented Dec 5, 2022

I propose to skip test_cmd_line_script.test_script_as_dev_fd() on FreeBSD. Here is why.

cc @Jehops @emaste @koobs

The test added by PR #99768 fails on FreeBSD. test_cmd_line_script.test_script_as_dev_fd() fails with:

FAIL: test_script_as_dev_fd (test.test_cmd_line_script.CmdLineTest.test_script_as_dev_fd)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/buildbot/python/3.x.koobs-freebsd-9e36.nondebug/build/Lib/test/test_cmd_line_script.py", line 766, in test_script_as_dev_fd
    self.assertEqual(out, b"12345678912345678912345\n")
AssertionError: b"/usr/home/buildbot/python/3.x.koobs-free[94 chars]ry\n" != b'12345678912345678912345\n'
Stderr:
/usr/home/buildbot/python/3.x.koobs-freebsd-9e36.nondebug/build/Lib/subprocess.py:849: RuntimeWarning: pass_fds overriding close_fds.
  warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)

Note: Failure first reported in issue #99985.

FreeBSD /dev/fd/ behaves differently than Linux /dev/fd/. I'm not sure why. If the parent opens a file and the file descriptor is inherited, the child process can open the file, but /dev/fd/ only contains file descriptors 0, 1, 2. Example:

parent.py:

import subprocess
import sys

script = 'print("Hello")'

script_name = 'script.py'
with open(script_name, 'w') as fp:
    fp.write(script)

with open(script_name, "r") as fp:
    fd = fp.fileno()
    print("FD", fd)

    cmd = [sys.executable]
    p = subprocess.Popen(cmd, close_fds=False, pass_fds=(0, 1, 2, fd))
    p.wait()

Child process:

$ ./python y.py 
FD 3

/usr/home/vstinner/python/main/Lib/subprocess.py:849: RuntimeWarning: pass_fds overriding close_fds.
  warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)

Python 3.12.0a2+ (heads/main:e3a3863cb9, Dec  5 2022, 12:09:39) [Clang 13.0.0 ([email protected]:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a3 on freebsd13
Type "help", "copyright", "credits" or "license" for more information.
>>> import os

# The process has 4 file descriptors:
>>> fd=os.dup(0); os.close(fd)
>>> fd=os.dup(1); os.close(fd)
>>> fd=os.dup(2); os.close(fd)
>>> fd=os.dup(3); os.close(fd)

# But /dev/fd/3 doesn't exist
>>> os.listdir("/dev/fd")
['0', '1', '2']

>>> f=open("/dev/fd/3", "rb")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/dev/fd/3'

# Using directly file descriptor 3 works as expected:
>>> f=open(3, "rb")
>>> f.close()

Linked PRs

@vstinner vstinner added the type-bug An unexpected behavior, bug, or error label Dec 5, 2022
vstinner added a commit that referenced this issue Dec 5, 2022
On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 5, 2022
…0006)

On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
(cherry picked from commit 038b151)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this issue Dec 5, 2022
On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
(cherry picked from commit 038b151)

Co-authored-by: Victor Stinner <[email protected]>
@vstinner vstinner closed this as completed Dec 5, 2022
@vstinner
Copy link
Member Author

vstinner commented Dec 5, 2022

Fixed by 038b151

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 8, 2024
…0006)

On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
(cherry picked from commit 038b151)

Co-authored-by: Victor Stinner <[email protected]>
pablogsal pushed a commit that referenced this issue Oct 22, 2024
…#125109)

gh-100005: Skip test_script_as_dev_fd() on FreeBSD (GH-100006)

On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if
fdescfs is not mounted (at /dev/fd).
(cherry picked from commit 038b151)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant