1
0
mirror of https://github.com/golang/go synced 2024-11-19 08:54:47 -07:00

os/signal: skip TestTerminalSignal if posix_openpt fails with EACCES

This happens in a chroot and so causes failures when packaging Go 1.10 for
Debian/Ubuntu.

Change-Id: I817038c237e584ce185b2168f8c7a10b9ef27b43
Reviewed-on: https://go-review.googlesource.com/90875
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2018-01-31 10:27:49 +13:00
parent d30591c18d
commit 03e10bd9c4
3 changed files with 23 additions and 4 deletions

View File

@ -301,7 +301,7 @@ var pkgDeps = map[string][]string{
"os/user": {"L4", "CGO", "io/ioutil", "os", "syscall"},
// Internal package used only for testing.
"os/signal/internal/pty": {"CGO", "fmt", "os"},
"os/signal/internal/pty": {"CGO", "fmt", "os", "syscall"},
// Basic networking.
// Because net must be used by any package that wants to

View File

@ -21,21 +21,36 @@ import "C"
import (
"fmt"
"os"
"syscall"
)
type PtyError struct {
FuncName string
ErrorString string
Errno syscall.Errno
}
func ptyError(name string, err error) *PtyError {
return &PtyError{name, err.Error(), err.(syscall.Errno)}
}
func (e *PtyError) Error() string {
return fmt.Sprintf("%s: %s", e.FuncName, e.ErrorString)
}
// Open returns a master pty and the name of the linked slave tty.
func Open() (master *os.File, slave string, err error) {
m, err := C.posix_openpt(C.O_RDWR)
if err != nil {
return nil, "", fmt.Errorf("posix_openpt: %v", err)
return nil, "", ptyError("posix_openpt", err)
}
if _, err := C.grantpt(m); err != nil {
C.close(m)
return nil, "", fmt.Errorf("grantpt: %v", err)
return nil, "", ptyError("grantpt", err)
}
if _, err := C.unlockpt(m); err != nil {
C.close(m)
return nil, "", fmt.Errorf("unlockpt: %v", err)
return nil, "", ptyError("unlockpt", err)
}
slave = C.GoString(C.ptsname(m))
return os.NewFile(uintptr(m), "pty-master"), slave, nil

View File

@ -72,6 +72,10 @@ func TestTerminalSignal(t *testing.T) {
master, sname, err := pty.Open()
if err != nil {
ptyErr := err.(*pty.PtyError)
if ptyErr.FuncName == "posix_openpt" && ptyErr.Errno == syscall.EACCES {
t.Skip("posix_openpt failed with EACCES, assuming chroot and skipping")
}
t.Fatal(err)
}
defer master.Close()