Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

File descriptors given to pass_fds should have close-on-exec flag unset #4

@jstewmon

Description

@jstewmon

Here's a script to reproduce the issue:

import os
import sys

if os.name == 'posix' and sys.version_info[0] < 3:
    import subprocess32 as subprocess
else:
    import subprocess

p1 = subprocess.Popen(['echo', 'hi'], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['echo', 'bye'], stdout=subprocess.PIPE)

# uncommenting these lines will produce expected result in python2.7
# subprocess._set_cloexec(p1.stdout.fileno(), False)
# subprocess._set_cloexec(p2.stdout.fileno(), False)

subs = [p1, p2]

fds = [i.stdout.fileno() for i in subs]
args = ['/dev/fd/{}'.format(fd) for fd in fds]

p2 = subprocess.Popen(
    ['cat'] + args,
    pass_fds=fds
)

python 3.5 output:

hi
bye

python 2.7 output:

cat: /dev/fd/3: No such file or directory
cat: /dev/fd/4: No such file or directory

My C isn't very good, but I traced through the _posixsubprocess.c and fileutils.c source on the 2.7 tag of cpython sources on GitHub, and it looks like it should be calling ioctl(fd, FIONCLEX, NULL) for each fd in pass_fds, so I haven't been able to figure out why this isn't working in python 2.7.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions