Skip to content

Commit

Permalink
runtime/testdata/testprog: use testenv.SyscallIsNotSupported to check…
Browse files Browse the repository at this point in the history
… syscall.Unshare

syscall.Unshare is the sort of system call that may be blocked in a
container environment, and experience has shown that different
container implementations choose from a variety of different error
codes for blocked syscalls.

In particular, the patch in
https://git.alpinelinux.org/aports/tree/community/go/tests-unshare-enosys.patch
seems to suggest that the container environment used to test the Go
distribution on Alpine Linux returns ENOSYS instead of EPERM.

The existing testenv.SyscallIsNotSupported helper checks for
the kinds of error codes we have seen from containers in practice, so
let's use that here.

For #62053.
Updates #29366.

Change-Id: Ic6755f7224fcdc0cb8b25dde2d6047ceb5c3ffdf
Reviewed-on: https://go-review.googlesource.com/c/go/+/520057
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills committed Aug 16, 2023
1 parent 9049d77 commit 9cf209f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/runtime/testdata/testprog/syscalls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
"internal/testenv"
"os"
"syscall"
)
Expand Down Expand Up @@ -44,11 +45,8 @@ func getcwd() (string, error) {

func unshareFs() error {
err := syscall.Unshare(syscall.CLONE_FS)
if err != nil {
errno, ok := err.(syscall.Errno)
if ok && errno == syscall.EPERM {
return errNotPermitted
}
if testenv.SyscallIsNotSupported(err) {
return errNotPermitted
}
return err
}
Expand Down

0 comments on commit 9cf209f

Please sign in to comment.