golang/go

os/exec: status of FDs >= len(cmd.ExtraFiles)+3 is undocumented

Open

#37,857 opened on Mar 14, 2020

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
DocumentationNeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What version of Go are you using (go version)?

go version go1.14 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOOS="linux"

What did you do?

Invocation: $ parent-cmd 0<a 1>b 2>c 3>d 4>e 5>f

cmd := exec.Command("child-cmd")
cmd.ExtraFiles = []*os.File{os.Stderr}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Start() // in child-cmd: 0=a 1=b 2=c 3=c 4=e 5=closed!

What did you expect to see?

File descriptors 4 and 5 (>= len(cmd.ExtraFiles)+3) to be either both inherited or none, and the behavior to be documented.

What did you see instead?

File descriptor 4 is inherited, but 5 is not. The doc doesn't say anything about FDs >= len(cmd.ExtraFiles)+3 in the child process.

Contributor guide