mirror of
https://github.com/golang/go
synced 2024-11-19 21:04:43 -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:
parent
d30591c18d
commit
03e10bd9c4
@ -301,7 +301,7 @@ var pkgDeps = map[string][]string{
|
|||||||
"os/user": {"L4", "CGO", "io/ioutil", "os", "syscall"},
|
"os/user": {"L4", "CGO", "io/ioutil", "os", "syscall"},
|
||||||
|
|
||||||
// Internal package used only for testing.
|
// Internal package used only for testing.
|
||||||
"os/signal/internal/pty": {"CGO", "fmt", "os"},
|
"os/signal/internal/pty": {"CGO", "fmt", "os", "syscall"},
|
||||||
|
|
||||||
// Basic networking.
|
// Basic networking.
|
||||||
// Because net must be used by any package that wants to
|
// Because net must be used by any package that wants to
|
||||||
|
@ -21,21 +21,36 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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.
|
// Open returns a master pty and the name of the linked slave tty.
|
||||||
func Open() (master *os.File, slave string, err error) {
|
func Open() (master *os.File, slave string, err error) {
|
||||||
m, err := C.posix_openpt(C.O_RDWR)
|
m, err := C.posix_openpt(C.O_RDWR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf("posix_openpt: %v", err)
|
return nil, "", ptyError("posix_openpt", err)
|
||||||
}
|
}
|
||||||
if _, err := C.grantpt(m); err != nil {
|
if _, err := C.grantpt(m); err != nil {
|
||||||
C.close(m)
|
C.close(m)
|
||||||
return nil, "", fmt.Errorf("grantpt: %v", err)
|
return nil, "", ptyError("grantpt", err)
|
||||||
}
|
}
|
||||||
if _, err := C.unlockpt(m); err != nil {
|
if _, err := C.unlockpt(m); err != nil {
|
||||||
C.close(m)
|
C.close(m)
|
||||||
return nil, "", fmt.Errorf("unlockpt: %v", err)
|
return nil, "", ptyError("unlockpt", err)
|
||||||
}
|
}
|
||||||
slave = C.GoString(C.ptsname(m))
|
slave = C.GoString(C.ptsname(m))
|
||||||
return os.NewFile(uintptr(m), "pty-master"), slave, nil
|
return os.NewFile(uintptr(m), "pty-master"), slave, nil
|
||||||
|
@ -72,6 +72,10 @@ func TestTerminalSignal(t *testing.T) {
|
|||||||
|
|
||||||
master, sname, err := pty.Open()
|
master, sname, err := pty.Open()
|
||||||
if err != nil {
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer master.Close()
|
defer master.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user