]> Cypherpunks repositories - gostls13.git/commitdiff
os: treat Getwd result of ENOMEM the same as ENAMETOOLONG
authorIan Lance Taylor <iant@golang.org>
Tue, 3 Sep 2024 22:13:01 +0000 (15:13 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 4 Sep 2024 00:53:44 +0000 (00:53 +0000)
We can see ENOMEM on FreeBSD.

Also don't fail the test if we get an EPERM error when reading
all the way up the tree; on Android we get that, perhaps because
the root directory is unreadable.

Also accept an EFAULT from a stat of a long name on Dragonfly,
which we see on the builders.

Change-Id: If37e6bf414b7b568c9a06130f71e79af153bfb75
Reviewed-on: https://go-review.googlesource.com/c/go/+/610415
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/os/error_errno.go
src/os/error_plan9.go
src/os/getwd.go
src/os/getwd_unix_test.go

index c4d540cdff09445ad36830ca017993f61f52ba56..662258338bd92904e13051e09f5fb7c317432775 100644 (file)
@@ -10,5 +10,8 @@ import "syscall"
 
 type syscallErrorType = syscall.Errno
 
-const errENOSYS = syscall.ENOSYS
-const errERANGE = syscall.ERANGE
+const (
+       errENOSYS = syscall.ENOSYS
+       errERANGE = syscall.ERANGE
+       errENOMEM = syscall.ENOMEM
+)
index 61b56211b4917b38c5c3b97cf605576ecd179551..35026554c27bcb8e1ab68a3fee129060f9086f82 100644 (file)
@@ -10,3 +10,4 @@ type syscallErrorType = syscall.ErrorString
 
 var errENOSYS = syscall.NewError("function not implemented")
 var errERANGE = syscall.NewError("out of range")
+var errENOMEM = syscall.NewError("cannot allocate memory")
index 8dca70fc2e582ed60c604fed9bd9d75882b296f4..82f0d944df97de1c108e1d16eab0ab54b35aebae 100644 (file)
@@ -60,9 +60,10 @@ func Getwd() (dir string, err error) {
                        }
                }
                // Linux returns ENAMETOOLONG if the result is too long.
-               // BSD systems appear to return EINVAL.
+               // Some BSD systems appear to return EINVAL.
+               // FreeBSD systems appear to use ENOMEM
                // Solaris appears to use ERANGE.
-               if err != syscall.ENAMETOOLONG && err != syscall.EINVAL && err != errERANGE {
+               if err != syscall.ENAMETOOLONG && err != syscall.EINVAL && err != errERANGE && err != errENOMEM {
                        return dir, NewSyscallError("getwd", err)
                }
        }
index a0c4f5bef1e591ccafbcf198460e887b94b5d462..084344735cf2ca30a7558f180bd2d67f891a4d54 100644 (file)
@@ -9,6 +9,7 @@ package os_test
 import (
        "errors"
        . "os"
+       "runtime"
        "strings"
        "syscall"
        "testing"
@@ -56,6 +57,12 @@ func testGetwdDeep(t *testing.T, setPWD bool) {
                wd, err := Getwd()
                t.Logf("Getwd len: %d", len(wd))
                if err != nil {
+                       // We can get an EPERM error if we can't read up
+                       // to root, which happens on the Android builders.
+                       if errors.Is(err, syscall.EPERM) {
+                               t.Logf("ignoring EPERM error: %v", err)
+                               break
+                       }
                        t.Fatal(err)
                }
                if setPWD && wd != dir {
@@ -72,7 +79,13 @@ func testGetwdDeep(t *testing.T, setPWD bool) {
                // all Unix platforms (4096, on Linux).
                if _, err := Stat(wd); err != nil || len(wd) > 4096 {
                        t.Logf("Done; len(wd)=%d", len(wd))
-                       if err != nil && !errors.Is(err, syscall.ENAMETOOLONG) {
+                       // Most systems return ENAMETOOLONG.
+                       // Dragonfly returns EFAULT.
+                       switch {
+                       case err == nil:
+                       case errors.Is(err, syscall.ENAMETOOLONG):
+                       case runtime.GOOS == "dragonfly" && errors.Is(err, syscall.EFAULT):
+                       default:
                                t.Fatalf("unexpected Stat error: %v", err)
                        }
                        break