diff options
Diffstat (limited to 'src/os/exec')
| -rw-r--r-- | src/os/exec/example_test.go | 3 | ||||
| -rw-r--r-- | src/os/exec/exec_plan9.go | 4 | ||||
| -rw-r--r-- | src/os/exec/exec_test.go | 25 | ||||
| -rw-r--r-- | src/os/exec/exec_unix.go | 4 | ||||
| -rw-r--r-- | src/os/exec/exec_windows.go | 4 | ||||
| -rw-r--r-- | src/os/exec/lp_plan9.go | 3 | ||||
| -rw-r--r-- | src/os/exec/lp_unix.go | 3 | ||||
| -rw-r--r-- | src/os/exec/lp_unix_test.go | 3 | ||||
| -rw-r--r-- | src/os/exec/lp_windows.go | 5 | ||||
| -rw-r--r-- | src/os/exec/lp_windows_test.go | 7 | ||||
| -rw-r--r-- | src/os/exec/read3.go | 8 |
11 files changed, 43 insertions, 26 deletions
diff --git a/src/os/exec/example_test.go b/src/os/exec/example_test.go index 62866fa710..a66890be69 100644 --- a/src/os/exec/example_test.go +++ b/src/os/exec/example_test.go @@ -10,7 +10,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -128,7 +127,7 @@ func ExampleCmd_StderrPipe() { log.Fatal(err) } - slurp, _ := ioutil.ReadAll(stderr) + slurp, _ := io.ReadAll(stderr) fmt.Printf("%s\n", slurp) if err := cmd.Wait(); err != nil { diff --git a/src/os/exec/exec_plan9.go b/src/os/exec/exec_plan9.go index d90bd04399..21ac7b765f 100644 --- a/src/os/exec/exec_plan9.go +++ b/src/os/exec/exec_plan9.go @@ -4,14 +4,14 @@ package exec -import "os" +import "io/fs" func init() { skipStdinCopyError = func(err error) bool { // Ignore hungup errors copying to stdin if the program // completed successfully otherwise. // See Issue 35753. - pe, ok := err.(*os.PathError) + pe, ok := err.(*fs.PathError) return ok && pe.Op == "write" && pe.Path == "|1" && pe.Err.Error() == "i/o on hungup channel" diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index dafbc64a17..8b0c93f382 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -15,7 +15,6 @@ import ( "internal/poll" "internal/testenv" "io" - "io/ioutil" "log" "net" "net/http" @@ -386,7 +385,7 @@ func TestPipeLookPathLeak(t *testing.T) { // Reading /proc/self/fd is more reliable than calling lsof, so try that // first. numOpenFDs := func() (int, []byte, error) { - fds, err := ioutil.ReadDir("/proc/self/fd") + fds, err := os.ReadDir("/proc/self/fd") if err != nil { return 0, nil, err } @@ -605,6 +604,10 @@ func TestExtraFiles(t *testing.T) { testenv.MustHaveExec(t) testenv.MustHaveGoBuild(t) + // This test runs with cgo disabled. External linking needs cgo, so + // it doesn't work if external linking is required. + testenv.MustInternalLink(t) + if runtime.GOOS == "windows" { t.Skipf("skipping test on %q", runtime.GOOS) } @@ -633,7 +636,7 @@ func TestExtraFiles(t *testing.T) { // cgo), to make sure none of that potential C code leaks fds. ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) // quiet expected TLS handshake error "remote error: bad certificate" - ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0) + ts.Config.ErrorLog = log.New(io.Discard, "", 0) ts.StartTLS() defer ts.Close() _, err = http.Get(ts.URL) @@ -641,7 +644,7 @@ func TestExtraFiles(t *testing.T) { t.Errorf("success trying to fetch %s; want an error", ts.URL) } - tf, err := ioutil.TempFile("", "") + tf, err := os.CreateTemp("", "") if err != nil { t.Fatalf("TempFile: %v", err) } @@ -687,6 +690,18 @@ func TestExtraFiles(t *testing.T) { c.Stdout = &stdout c.Stderr = &stderr c.ExtraFiles = []*os.File{tf} + if runtime.GOOS == "illumos" { + // Some facilities in illumos are implemented via access + // to /proc by libc; such accesses can briefly occupy a + // low-numbered fd. If this occurs concurrently with the + // test that checks for leaked descriptors, the check can + // become confused and report a spurious leaked descriptor. + // (See issue #42431 for more detailed analysis.) + // + // Attempt to constrain the use of additional threads in the + // child process to make this test less flaky: + c.Env = append(os.Environ(), "GOMAXPROCS=1") + } err = c.Run() if err != nil { t.Fatalf("Run: %v\n--- stdout:\n%s--- stderr:\n%s", err, stdout.Bytes(), stderr.Bytes()) @@ -826,7 +841,7 @@ func TestHelperProcess(*testing.T) { } } case "stdinClose": - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) os.Exit(1) diff --git a/src/os/exec/exec_unix.go b/src/os/exec/exec_unix.go index 9c3e17d23a..51c52427c2 100644 --- a/src/os/exec/exec_unix.go +++ b/src/os/exec/exec_unix.go @@ -7,7 +7,7 @@ package exec import ( - "os" + "io/fs" "syscall" ) @@ -16,7 +16,7 @@ func init() { // Ignore EPIPE errors copying to stdin if the program // completed successfully otherwise. // See Issue 9173. - pe, ok := err.(*os.PathError) + pe, ok := err.(*fs.PathError) return ok && pe.Op == "write" && pe.Path == "|1" && pe.Err == syscall.EPIPE diff --git a/src/os/exec/exec_windows.go b/src/os/exec/exec_windows.go index af8cd97218..bb937f8aed 100644 --- a/src/os/exec/exec_windows.go +++ b/src/os/exec/exec_windows.go @@ -5,7 +5,7 @@ package exec import ( - "os" + "io/fs" "syscall" ) @@ -15,7 +15,7 @@ func init() { // to stdin if the program completed successfully otherwise. // See Issue 20445. const _ERROR_NO_DATA = syscall.Errno(0xe8) - pe, ok := err.(*os.PathError) + pe, ok := err.(*fs.PathError) return ok && pe.Op == "write" && pe.Path == "|1" && (pe.Err == syscall.ERROR_BROKEN_PIPE || pe.Err == _ERROR_NO_DATA) diff --git a/src/os/exec/lp_plan9.go b/src/os/exec/lp_plan9.go index 5860cbca4d..e8826a5083 100644 --- a/src/os/exec/lp_plan9.go +++ b/src/os/exec/lp_plan9.go @@ -6,6 +6,7 @@ package exec import ( "errors" + "io/fs" "os" "path/filepath" "strings" @@ -22,7 +23,7 @@ func findExecutable(file string) error { if m := d.Mode(); !m.IsDir() && m&0111 != 0 { return nil } - return os.ErrPermission + return fs.ErrPermission } // LookPath searches for an executable named file in the diff --git a/src/os/exec/lp_unix.go b/src/os/exec/lp_unix.go index 93793e0eee..66c1df76fb 100644 --- a/src/os/exec/lp_unix.go +++ b/src/os/exec/lp_unix.go @@ -8,6 +8,7 @@ package exec import ( "errors" + "io/fs" "os" "path/filepath" "strings" @@ -24,7 +25,7 @@ func findExecutable(file string) error { if m := d.Mode(); !m.IsDir() && m&0111 != 0 { return nil } - return os.ErrPermission + return fs.ErrPermission } // LookPath searches for an executable named file in the diff --git a/src/os/exec/lp_unix_test.go b/src/os/exec/lp_unix_test.go index e4656cafb8..296480fd04 100644 --- a/src/os/exec/lp_unix_test.go +++ b/src/os/exec/lp_unix_test.go @@ -7,13 +7,12 @@ package exec import ( - "io/ioutil" "os" "testing" ) func TestLookPathUnixEmptyPath(t *testing.T) { - tmp, err := ioutil.TempDir("", "TestLookPathUnixEmptyPath") + tmp, err := os.MkdirTemp("", "TestLookPathUnixEmptyPath") if err != nil { t.Fatal("TempDir failed: ", err) } diff --git a/src/os/exec/lp_windows.go b/src/os/exec/lp_windows.go index 9ea3d76575..e7a2cdf142 100644 --- a/src/os/exec/lp_windows.go +++ b/src/os/exec/lp_windows.go @@ -6,6 +6,7 @@ package exec import ( "errors" + "io/fs" "os" "path/filepath" "strings" @@ -20,7 +21,7 @@ func chkStat(file string) error { return err } if d.IsDir() { - return os.ErrPermission + return fs.ErrPermission } return nil } @@ -47,7 +48,7 @@ func findExecutable(file string, exts []string) (string, error) { return f, nil } } - return "", os.ErrNotExist + return "", fs.ErrNotExist } // LookPath searches for an executable named file in the diff --git a/src/os/exec/lp_windows_test.go b/src/os/exec/lp_windows_test.go index 59b5f1c2c7..c6f3d5d406 100644 --- a/src/os/exec/lp_windows_test.go +++ b/src/os/exec/lp_windows_test.go @@ -11,7 +11,6 @@ import ( "fmt" "internal/testenv" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -307,7 +306,7 @@ var lookPathTests = []lookPathTest{ } func TestLookPath(t *testing.T) { - tmp, err := ioutil.TempDir("", "TestLookPath") + tmp, err := os.MkdirTemp("", "TestLookPath") if err != nil { t.Fatal("TempDir failed: ", err) } @@ -504,7 +503,7 @@ var commandTests = []commandTest{ } func TestCommand(t *testing.T) { - tmp, err := ioutil.TempDir("", "TestCommand") + tmp, err := os.MkdirTemp("", "TestCommand") if err != nil { t.Fatal("TempDir failed: ", err) } @@ -529,7 +528,7 @@ func TestCommand(t *testing.T) { func buildPrintPathExe(t *testing.T, dir string) string { const name = "printpath" srcname := name + ".go" - err := ioutil.WriteFile(filepath.Join(dir, srcname), []byte(printpathSrc), 0644) + err := os.WriteFile(filepath.Join(dir, srcname), []byte(printpathSrc), 0644) if err != nil { t.Fatalf("failed to create source: %v", err) } diff --git a/src/os/exec/read3.go b/src/os/exec/read3.go index 25d732a991..8cc24da8cb 100644 --- a/src/os/exec/read3.go +++ b/src/os/exec/read3.go @@ -15,7 +15,7 @@ package main import ( "fmt" "internal/poll" - "io/ioutil" + "io" "os" "os/exec" "runtime" @@ -24,7 +24,7 @@ import ( func main() { fd3 := os.NewFile(3, "fd3") - bs, err := ioutil.ReadAll(fd3) + bs, err := io.ReadAll(fd3) if err != nil { fmt.Printf("ReadAll from fd 3: %v\n", err) os.Exit(1) @@ -56,7 +56,7 @@ func main() { switch runtime.GOOS { case "plan9": args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())} - case "aix": + case "aix", "solaris", "illumos": args = []string{fmt.Sprint(os.Getpid())} default: args = []string{"-p", fmt.Sprint(os.Getpid())} @@ -71,6 +71,8 @@ func main() { ofcmd = "/bin/cat" case "aix": ofcmd = "procfiles" + case "solaris", "illumos": + ofcmd = "pfiles" } cmd := exec.Command(ofcmd, args...) |
