From 178be83e0eb465156be32c69e59aba0f815fb746 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 19 Dec 2011 09:23:07 -0800 Subject: [PATCH] exec: add test to verify net package's epoll fd doesn't go to child R=rsc CC=golang-dev https://golang.org/cl/5490075 --- src/pkg/os/exec/exec_test.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go index d26127c7af..4cd346a68b 100644 --- a/src/pkg/os/exec/exec_test.go +++ b/src/pkg/os/exec/exec_test.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "io/ioutil" + "net" "os" "runtime" "strconv" @@ -146,6 +147,15 @@ func TestExtraFiles(t *testing.T) { t.Logf("no operating system support; skipping") return } + + // Force network usage, to verify the epoll (or whatever) fd + // doesn't leak to the child, + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + tf, err := ioutil.TempFile("", "") if err != nil { t.Fatalf("TempFile: %v", err) @@ -167,7 +177,7 @@ func TestExtraFiles(t *testing.T) { c.ExtraFiles = []*os.File{tf} bs, err := c.CombinedOutput() if err != nil { - t.Fatalf("CombinedOutput: %v", err) + t.Fatalf("CombinedOutput: %v; output %q", err, bs) } if string(bs) != text { t.Errorf("got %q; want %q", string(bs), text) @@ -246,6 +256,29 @@ func TestHelperProcess(*testing.T) { fmt.Printf("ReadAll from fd 3: %v", err) os.Exit(1) } + // TODO(bradfitz,iant): the rest of this test is disabled + // for now. remove this block once 5494061 is in. + { + os.Stderr.Write(bs) + os.Exit(0) + } + // Now verify that there are no other open fds. + var files []*os.File + for wantfd := os.Stderr.Fd() + 2; wantfd <= 100; wantfd++ { + f, err := os.Open(os.Args[0]) + if err != nil { + fmt.Printf("error opening file with expected fd %d: %v", wantfd, err) + os.Exit(1) + } + if got := f.Fd(); got != wantfd { + fmt.Printf("leaked parent file. fd = %d; want %d", got, wantfd) + os.Exit(1) + } + files = append(files, f) + } + for _, f := range files { + f.Close() + } os.Stderr.Write(bs) case "exit": n, _ := strconv.Atoi(args[0]) -- 2.48.1