diff --git a/go.mod b/go.mod index f4d7473..b0253cf 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/elisescu/tty-share go 1.18 require ( - github.com/elisescu/pty v1.0.2 + github.com/creack/pty v1.1.11 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 github.com/hashicorp/yamux v0.1.1 diff --git a/go.sum b/go.sum index 0a1f5d0..5ec0ef9 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,10 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/elisescu/pty v1.0.2 h1:I/wkN5bnPyh00j/bnNAy8wll8yvd8wRLUjPnmcmYI+Q= -github.com/elisescu/pty v1.0.2/go.mod h1:tzLUboZf84k7sFZdd2cOvhr/fSxMABV0UTMxnF25R/Y= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/pty_master.go b/pty_master.go index 487e3c9..599519a 100644 --- a/pty_master.go +++ b/pty_master.go @@ -7,7 +7,7 @@ import ( "syscall" "time" - ptyDevice "github.com/elisescu/pty" + ptyDevice "github.com/creack/pty" log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh/terminal" ) @@ -101,7 +101,11 @@ func (pty *ptyMaster) Read(b []byte) (int, error) { } func (pty *ptyMaster) SetWinSize(rows, cols int) { - ptyDevice.Setsize(pty.ptyFile, rows, cols) + winSize := ptyDevice.Winsize{ + Rows: uint16(rows), + Cols: uint16(cols), + } + ptyDevice.Setsize(pty.ptyFile, &winSize) } func (pty *ptyMaster) Refresh() { diff --git a/vendor/github.com/elisescu/pty/.gitignore b/vendor/github.com/creack/pty/.gitignore similarity index 100% rename from vendor/github.com/elisescu/pty/.gitignore rename to vendor/github.com/creack/pty/.gitignore diff --git a/vendor/github.com/creack/pty/Dockerfile.riscv b/vendor/github.com/creack/pty/Dockerfile.riscv new file mode 100644 index 0000000..adfdf82 --- /dev/null +++ b/vendor/github.com/creack/pty/Dockerfile.riscv @@ -0,0 +1,14 @@ +FROM golang:1.13 + +# Clone and complie a riscv compatible version of the go compiler. +RUN git clone https://review.gerrithub.io/riscv/riscv-go /riscv-go +# riscvdev branch HEAD as of 2019-06-29. +RUN cd /riscv-go && git checkout 04885fddd096d09d4450726064d06dd107e374bf +ENV PATH=/riscv-go/misc/riscv:/riscv-go/bin:$PATH +RUN cd /riscv-go/src && GOROOT_BOOTSTRAP=$(go env GOROOT) ./make.bash +ENV GOROOT=/riscv-go + +# Make sure we compile. +WORKDIR pty +ADD . . +RUN GOOS=linux GOARCH=riscv go build diff --git a/vendor/github.com/elisescu/pty/License b/vendor/github.com/creack/pty/LICENSE similarity index 100% rename from vendor/github.com/elisescu/pty/License rename to vendor/github.com/creack/pty/LICENSE diff --git a/vendor/github.com/creack/pty/README.md b/vendor/github.com/creack/pty/README.md new file mode 100644 index 0000000..5275014 --- /dev/null +++ b/vendor/github.com/creack/pty/README.md @@ -0,0 +1,100 @@ +# pty + +Pty is a Go package for using unix pseudo-terminals. + +## Install + + go get github.com/creack/pty + +## Example + +### Command + +```go +package main + +import ( + "github.com/creack/pty" + "io" + "os" + "os/exec" +) + +func main() { + c := exec.Command("grep", "--color=auto", "bar") + f, err := pty.Start(c) + if err != nil { + panic(err) + } + + go func() { + f.Write([]byte("foo\n")) + f.Write([]byte("bar\n")) + f.Write([]byte("baz\n")) + f.Write([]byte{4}) // EOT + }() + io.Copy(os.Stdout, f) +} +``` + +### Shell + +```go +package main + +import ( + "io" + "log" + "os" + "os/exec" + "os/signal" + "syscall" + + "github.com/creack/pty" + "golang.org/x/crypto/ssh/terminal" +) + +func test() error { + // Create arbitrary command. + c := exec.Command("bash") + + // Start the command with a pty. + ptmx, err := pty.Start(c) + if err != nil { + return err + } + // Make sure to close the pty at the end. + defer func() { _ = ptmx.Close() }() // Best effort. + + // Handle pty size. + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGWINCH) + go func() { + for range ch { + if err := pty.InheritSize(os.Stdin, ptmx); err != nil { + log.Printf("error resizing pty: %s", err) + } + } + }() + ch <- syscall.SIGWINCH // Initial resize. + + // Set stdin in raw mode. + oldState, err := terminal.MakeRaw(int(os.Stdin.Fd())) + if err != nil { + panic(err) + } + defer func() { _ = terminal.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort. + + // Copy stdin to the pty and the pty to stdout. + go func() { _, _ = io.Copy(ptmx, os.Stdin) }() + _, _ = io.Copy(os.Stdout, ptmx) + + return nil +} + +func main() { + if err := test(); err != nil { + log.Fatal(err) + } +} +``` diff --git a/vendor/github.com/elisescu/pty/doc.go b/vendor/github.com/creack/pty/doc.go similarity index 100% rename from vendor/github.com/elisescu/pty/doc.go rename to vendor/github.com/creack/pty/doc.go diff --git a/vendor/github.com/elisescu/pty/ioctl.go b/vendor/github.com/creack/pty/ioctl.go similarity index 86% rename from vendor/github.com/elisescu/pty/ioctl.go rename to vendor/github.com/creack/pty/ioctl.go index c57c19e..c85cdcd 100644 --- a/vendor/github.com/elisescu/pty/ioctl.go +++ b/vendor/github.com/creack/pty/ioctl.go @@ -1,4 +1,4 @@ -// +build !windows +// +build !windows,!solaris package pty diff --git a/vendor/github.com/elisescu/pty/ioctl_bsd.go b/vendor/github.com/creack/pty/ioctl_bsd.go similarity index 100% rename from vendor/github.com/elisescu/pty/ioctl_bsd.go rename to vendor/github.com/creack/pty/ioctl_bsd.go diff --git a/vendor/github.com/creack/pty/ioctl_solaris.go b/vendor/github.com/creack/pty/ioctl_solaris.go new file mode 100644 index 0000000..f63985f --- /dev/null +++ b/vendor/github.com/creack/pty/ioctl_solaris.go @@ -0,0 +1,30 @@ +package pty + +import ( + "golang.org/x/sys/unix" + "unsafe" +) + +const ( + // see /usr/include/sys/stropts.h + I_PUSH = uintptr((int32('S')<<8 | 002)) + I_STR = uintptr((int32('S')<<8 | 010)) + I_FIND = uintptr((int32('S')<<8 | 013)) + // see /usr/include/sys/ptms.h + ISPTM = (int32('P') << 8) | 1 + UNLKPT = (int32('P') << 8) | 2 + PTSSTTY = (int32('P') << 8) | 3 + ZONEPT = (int32('P') << 8) | 4 + OWNERPT = (int32('P') << 8) | 5 +) + +type strioctl struct { + ic_cmd int32 + ic_timout int32 + ic_len int32 + ic_dp unsafe.Pointer +} + +func ioctl(fd, cmd, ptr uintptr) error { + return unix.IoctlSetInt(int(fd), uint(cmd), int(ptr)) +} diff --git a/vendor/github.com/elisescu/pty/mktypes.bash b/vendor/github.com/creack/pty/mktypes.bash similarity index 91% rename from vendor/github.com/elisescu/pty/mktypes.bash rename to vendor/github.com/creack/pty/mktypes.bash index 0c07680..82ee167 100644 --- a/vendor/github.com/elisescu/pty/mktypes.bash +++ b/vendor/github.com/creack/pty/mktypes.bash @@ -13,7 +13,7 @@ GODEFS="go tool cgo -godefs" $GODEFS types.go |gofmt > ztypes_$GOARCH.go case $GOOS in -freebsd|dragonfly) +freebsd|dragonfly|openbsd) $GODEFS types_$GOOS.go |gofmt > ztypes_$GOOSARCH.go ;; esac diff --git a/vendor/github.com/elisescu/pty/pty_darwin.go b/vendor/github.com/creack/pty/pty_darwin.go similarity index 82% rename from vendor/github.com/elisescu/pty/pty_darwin.go rename to vendor/github.com/creack/pty/pty_darwin.go index 9341543..6344b6b 100644 --- a/vendor/github.com/elisescu/pty/pty_darwin.go +++ b/vendor/github.com/creack/pty/pty_darwin.go @@ -13,19 +13,23 @@ func open() (pty, tty *os.File, err error) { return nil, nil, err } p := os.NewFile(uintptr(pFD), "/dev/ptmx") + // In case of error after this point, make sure we close the ptmx fd. + defer func() { + if err != nil { + _ = p.Close() // Best effort. + } + }() sname, err := ptsname(p) if err != nil { return nil, nil, err } - err = grantpt(p) - if err != nil { + if err := grantpt(p); err != nil { return nil, nil, err } - err = unlockpt(p) - if err != nil { + if err := unlockpt(p); err != nil { return nil, nil, err } diff --git a/vendor/github.com/elisescu/pty/pty_dragonfly.go b/vendor/github.com/creack/pty/pty_dragonfly.go similarity index 86% rename from vendor/github.com/elisescu/pty/pty_dragonfly.go rename to vendor/github.com/creack/pty/pty_dragonfly.go index 5431fb5..b7d1f20 100644 --- a/vendor/github.com/elisescu/pty/pty_dragonfly.go +++ b/vendor/github.com/creack/pty/pty_dragonfly.go @@ -14,19 +14,23 @@ func open() (pty, tty *os.File, err error) { if err != nil { return nil, nil, err } + // In case of error after this point, make sure we close the ptmx fd. + defer func() { + if err != nil { + _ = p.Close() // Best effort. + } + }() sname, err := ptsname(p) if err != nil { return nil, nil, err } - err = grantpt(p) - if err != nil { + if err := grantpt(p); err != nil { return nil, nil, err } - err = unlockpt(p) - if err != nil { + if err := unlockpt(p); err != nil { return nil, nil, err } diff --git a/vendor/github.com/elisescu/pty/pty_freebsd.go b/vendor/github.com/creack/pty/pty_freebsd.go similarity index 72% rename from vendor/github.com/elisescu/pty/pty_freebsd.go rename to vendor/github.com/creack/pty/pty_freebsd.go index b341bab..63b6d91 100644 --- a/vendor/github.com/elisescu/pty/pty_freebsd.go +++ b/vendor/github.com/creack/pty/pty_freebsd.go @@ -7,22 +7,28 @@ import ( "unsafe" ) -func posix_openpt(oflag int) (fd int, err error) { +func posixOpenpt(oflag int) (fd int, err error) { r0, _, e1 := syscall.Syscall(syscall.SYS_POSIX_OPENPT, uintptr(oflag), 0, 0) fd = int(r0) if e1 != 0 { err = e1 } - return + return fd, err } func open() (pty, tty *os.File, err error) { - fd, err := posix_openpt(syscall.O_RDWR | syscall.O_CLOEXEC) + fd, err := posixOpenpt(syscall.O_RDWR | syscall.O_CLOEXEC) if err != nil { return nil, nil, err } - p := os.NewFile(uintptr(fd), "/dev/pts") + // In case of error after this point, make sure we close the pts fd. + defer func() { + if err != nil { + _ = p.Close() // Best effort. + } + }() + sname, err := ptsname(p) if err != nil { return nil, nil, err @@ -42,7 +48,7 @@ func isptmaster(fd uintptr) (bool, error) { var ( emptyFiodgnameArg fiodgnameArg - ioctl_FIODGNAME = _IOW('f', 120, unsafe.Sizeof(emptyFiodgnameArg)) + ioctlFIODGNAME = _IOW('f', 120, unsafe.Sizeof(emptyFiodgnameArg)) ) func ptsname(f *os.File) (string, error) { @@ -59,8 +65,7 @@ func ptsname(f *os.File) (string, error) { buf = make([]byte, n) arg = fiodgnameArg{Len: n, Buf: (*byte)(unsafe.Pointer(&buf[0]))} ) - err = ioctl(f.Fd(), ioctl_FIODGNAME, uintptr(unsafe.Pointer(&arg))) - if err != nil { + if err := ioctl(f.Fd(), ioctlFIODGNAME, uintptr(unsafe.Pointer(&arg))); err != nil { return "", err } diff --git a/vendor/github.com/elisescu/pty/pty_linux.go b/vendor/github.com/creack/pty/pty_linux.go similarity index 75% rename from vendor/github.com/elisescu/pty/pty_linux.go rename to vendor/github.com/creack/pty/pty_linux.go index cb901a2..4a833de 100644 --- a/vendor/github.com/elisescu/pty/pty_linux.go +++ b/vendor/github.com/creack/pty/pty_linux.go @@ -12,14 +12,19 @@ func open() (pty, tty *os.File, err error) { if err != nil { return nil, nil, err } + // In case of error after this point, make sure we close the ptmx fd. + defer func() { + if err != nil { + _ = p.Close() // Best effort. + } + }() sname, err := ptsname(p) if err != nil { return nil, nil, err } - err = unlockpt(p) - if err != nil { + if err := unlockpt(p); err != nil { return nil, nil, err } @@ -41,6 +46,6 @@ func ptsname(f *os.File) (string, error) { func unlockpt(f *os.File) error { var u _C_int - // use TIOCSPTLCK with a zero valued arg to clear the slave pty lock + // use TIOCSPTLCK with a pointer to zero to clear the lock return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u))) } diff --git a/vendor/github.com/creack/pty/pty_openbsd.go b/vendor/github.com/creack/pty/pty_openbsd.go new file mode 100644 index 0000000..a6a35d1 --- /dev/null +++ b/vendor/github.com/creack/pty/pty_openbsd.go @@ -0,0 +1,33 @@ +package pty + +import ( + "os" + "syscall" + "unsafe" +) + +func open() (pty, tty *os.File, err error) { + /* + * from ptm(4): + * The PTMGET command allocates a free pseudo terminal, changes its + * ownership to the caller, revokes the access privileges for all previous + * users, opens the file descriptors for the pty and tty devices and + * returns them to the caller in struct ptmget. + */ + + p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0) + if err != nil { + return nil, nil, err + } + defer p.Close() + + var ptm ptmget + if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil { + return nil, nil, err + } + + pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm") + tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm") + + return pty, tty, nil +} diff --git a/vendor/github.com/creack/pty/pty_solaris.go b/vendor/github.com/creack/pty/pty_solaris.go new file mode 100644 index 0000000..09ec1b7 --- /dev/null +++ b/vendor/github.com/creack/pty/pty_solaris.go @@ -0,0 +1,139 @@ +package pty + +/* based on: +http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc/port/gen/pt.c +*/ + +import ( + "errors" + "golang.org/x/sys/unix" + "os" + "strconv" + "syscall" + "unsafe" +) + +const NODEV = ^uint64(0) + +func open() (pty, tty *os.File, err error) { + masterfd, err := syscall.Open("/dev/ptmx", syscall.O_RDWR|unix.O_NOCTTY, 0) + //masterfd, err := syscall.Open("/dev/ptmx", syscall.O_RDWR|syscall.O_CLOEXEC|unix.O_NOCTTY, 0) + if err != nil { + return nil, nil, err + } + p := os.NewFile(uintptr(masterfd), "/dev/ptmx") + + sname, err := ptsname(p) + if err != nil { + return nil, nil, err + } + + err = grantpt(p) + if err != nil { + return nil, nil, err + } + + err = unlockpt(p) + if err != nil { + return nil, nil, err + } + + slavefd, err := syscall.Open(sname, os.O_RDWR|unix.O_NOCTTY, 0) + if err != nil { + return nil, nil, err + } + t := os.NewFile(uintptr(slavefd), sname) + + // pushing terminal driver STREAMS modules as per pts(7) + for _, mod := range([]string{"ptem", "ldterm", "ttcompat"}) { + err = streams_push(t, mod) + if err != nil { + return nil, nil, err + } + } + + return p, t, nil +} + +func minor(x uint64) uint64 { + return x & 0377 +} + +func ptsdev(fd uintptr) uint64 { + istr := strioctl{ISPTM, 0, 0, nil} + err := ioctl(fd, I_STR, uintptr(unsafe.Pointer(&istr))) + if err != nil { + return NODEV + } + var status unix.Stat_t + err = unix.Fstat(int(fd), &status) + if err != nil { + return NODEV + } + return uint64(minor(status.Rdev)) +} + +func ptsname(f *os.File) (string, error) { + dev := ptsdev(f.Fd()) + if dev == NODEV { + return "", errors.New("not a master pty") + } + fn := "/dev/pts/" + strconv.FormatInt(int64(dev), 10) + // access(2) creates the slave device (if the pty exists) + // F_OK == 0 (unistd.h) + err := unix.Access(fn, 0) + if err != nil { + return "", err + } + return fn, nil +} + +type pt_own struct { + pto_ruid int32 + pto_rgid int32 +} + +func grantpt(f *os.File) error { + if ptsdev(f.Fd()) == NODEV { + return errors.New("not a master pty") + } + var pto pt_own + pto.pto_ruid = int32(os.Getuid()) + // XXX should first attempt to get gid of DEFAULT_TTY_GROUP="tty" + pto.pto_rgid = int32(os.Getgid()) + var istr strioctl + istr.ic_cmd = OWNERPT + istr.ic_timout = 0 + istr.ic_len = int32(unsafe.Sizeof(istr)) + istr.ic_dp = unsafe.Pointer(&pto) + err := ioctl(f.Fd(), I_STR, uintptr(unsafe.Pointer(&istr))) + if err != nil { + return errors.New("access denied") + } + return nil +} + +func unlockpt(f *os.File) error { + istr := strioctl{UNLKPT, 0, 0, nil} + return ioctl(f.Fd(), I_STR, uintptr(unsafe.Pointer(&istr))) +} + +// push STREAMS modules if not already done so +func streams_push(f *os.File, mod string) error { + var err error + buf := []byte(mod) + // XXX I_FIND is not returning an error when the module + // is already pushed even though truss reports a return + // value of 1. A bug in the Go Solaris syscall interface? + // XXX without this we are at risk of the issue + // https://www.illumos.org/issues/9042 + // but since we are not using libc or XPG4.2, we should not be + // double-pushing modules + + err = ioctl(f.Fd(), I_FIND, uintptr(unsafe.Pointer(&buf[0]))) + if err != nil { + return nil + } + err = ioctl(f.Fd(), I_PUSH, uintptr(unsafe.Pointer(&buf[0]))) + return err +} diff --git a/vendor/github.com/elisescu/pty/pty_unsupported.go b/vendor/github.com/creack/pty/pty_unsupported.go similarity index 64% rename from vendor/github.com/elisescu/pty/pty_unsupported.go rename to vendor/github.com/creack/pty/pty_unsupported.go index bd3d1e7..ceb425b 100644 --- a/vendor/github.com/elisescu/pty/pty_unsupported.go +++ b/vendor/github.com/creack/pty/pty_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux,!darwin,!freebsd,!dragonfly +// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd,!solaris package pty diff --git a/vendor/github.com/creack/pty/run.go b/vendor/github.com/creack/pty/run.go new file mode 100644 index 0000000..b079425 --- /dev/null +++ b/vendor/github.com/creack/pty/run.go @@ -0,0 +1,74 @@ +// +build !windows + +package pty + +import ( + "os" + "os/exec" + "syscall" +) + +// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// Starts the process in a new session and sets the controlling terminal. +func Start(c *exec.Cmd) (pty *os.File, err error) { + return StartWithSize(c, nil) +} + +// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// This will resize the pty to the specified size before starting the command. +// Starts the process in a new session and sets the controlling terminal. +func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { + if c.SysProcAttr == nil { + c.SysProcAttr = &syscall.SysProcAttr{} + } + c.SysProcAttr.Setsid = true + c.SysProcAttr.Setctty = true + return StartWithAttrs(c, sz, c.SysProcAttr) +} + +// StartWithAttrs assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, +// and c.Stderr, calls c.Start, and returns the File of the tty's +// corresponding pty. +// +// This will resize the pty to the specified size before starting the command if a size is provided. +// The `attrs` parameter overrides the one set in c.SysProcAttr. +// +// This should generally not be needed. Used in some edge cases where it is needed to create a pty +// without a controlling terminal. +func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (pty *os.File, err error) { + pty, tty, err := Open() + if err != nil { + return nil, err + } + defer tty.Close() + + if sz != nil { + if err := Setsize(pty, sz); err != nil { + pty.Close() + return nil, err + } + } + if c.Stdout == nil { + c.Stdout = tty + } + if c.Stderr == nil { + c.Stderr = tty + } + if c.Stdin == nil { + c.Stdin = tty + } + + c.SysProcAttr = attrs + + if err := c.Start(); err != nil { + _ = pty.Close() + return nil, err + } + return pty, err +} diff --git a/vendor/github.com/creack/pty/test_crosscompile.sh b/vendor/github.com/creack/pty/test_crosscompile.sh new file mode 100644 index 0000000..c4b9e37 --- /dev/null +++ b/vendor/github.com/creack/pty/test_crosscompile.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env sh + +# Test script checking that all expected os/arch compile properly. +# Does not actually test the logic, just the compilation so we make sure we don't break code depending on the lib. + +echo2() { + echo $@ >&2 +} + +trap end 0 +end() { + [ "$?" = 0 ] && echo2 "Pass." || (echo2 "Fail."; exit 1) +} + +cross() { + os=$1 + shift + echo2 "Build for $os." + for arch in $@; do + echo2 " - $os/$arch" + GOOS=$os GOARCH=$arch go build + done + echo2 +} + +set -e + +cross linux amd64 386 arm arm64 ppc64 ppc64le s390x mips mipsle mips64 mips64le +cross darwin amd64 386 arm arm64 +cross freebsd amd64 386 arm +cross netbsd amd64 386 arm +cross openbsd amd64 386 arm arm64 +cross dragonfly amd64 +cross solaris amd64 + +# Not expected to work but should still compile. +cross windows amd64 386 arm + +# TODO: Fix compilation error on openbsd/arm. +# TODO: Merge the solaris PR. + +# Some os/arch require a different compiler. Run in docker. +if ! hash docker; then + # If docker is not present, stop here. + return +fi + +echo2 "Build for linux." +echo2 " - linux/riscv" +docker build -t test -f Dockerfile.riscv . diff --git a/vendor/github.com/creack/pty/util.go b/vendor/github.com/creack/pty/util.go new file mode 100644 index 0000000..8fdde0b --- /dev/null +++ b/vendor/github.com/creack/pty/util.go @@ -0,0 +1,64 @@ +// +build !windows,!solaris + +package pty + +import ( + "os" + "syscall" + "unsafe" +) + +// InheritSize applies the terminal size of pty to tty. This should be run +// in a signal handler for syscall.SIGWINCH to automatically resize the tty when +// the pty receives a window size change notification. +func InheritSize(pty, tty *os.File) error { + size, err := GetsizeFull(pty) + if err != nil { + return err + } + err = Setsize(tty, size) + if err != nil { + return err + } + return nil +} + +// Setsize resizes t to s. +func Setsize(t *os.File, ws *Winsize) error { + return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ) +} + +// GetsizeFull returns the full terminal size description. +func GetsizeFull(t *os.File) (size *Winsize, err error) { + var ws Winsize + err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ) + return &ws, err +} + +// Getsize returns the number of rows (lines) and cols (positions +// in each line) in terminal t. +func Getsize(t *os.File) (rows, cols int, err error) { + ws, err := GetsizeFull(t) + return int(ws.Rows), int(ws.Cols), err +} + +// Winsize describes the terminal size. +type Winsize struct { + Rows uint16 // ws_row: Number of rows (in cells) + Cols uint16 // ws_col: Number of columns (in cells) + X uint16 // ws_xpixel: Width in pixels + Y uint16 // ws_ypixel: Height in pixels +} + +func windowRectCall(ws *Winsize, fd, a2 uintptr) error { + _, _, errno := syscall.Syscall( + syscall.SYS_IOCTL, + fd, + a2, + uintptr(unsafe.Pointer(ws)), + ) + if errno != 0 { + return syscall.Errno(errno) + } + return nil +} diff --git a/vendor/github.com/creack/pty/util_solaris.go b/vendor/github.com/creack/pty/util_solaris.go new file mode 100644 index 0000000..e889692 --- /dev/null +++ b/vendor/github.com/creack/pty/util_solaris.go @@ -0,0 +1,51 @@ +// + +package pty + +import ( + "os" + "golang.org/x/sys/unix" +) + +const ( + TIOCGWINSZ = 21608 // 'T' << 8 | 104 + TIOCSWINSZ = 21607 // 'T' << 8 | 103 +) + +// Winsize describes the terminal size. +type Winsize struct { + Rows uint16 // ws_row: Number of rows (in cells) + Cols uint16 // ws_col: Number of columns (in cells) + X uint16 // ws_xpixel: Width in pixels + Y uint16 // ws_ypixel: Height in pixels +} + +// GetsizeFull returns the full terminal size description. +func GetsizeFull(t *os.File) (size *Winsize, err error) { + var wsz *unix.Winsize + wsz, err = unix.IoctlGetWinsize(int(t.Fd()), TIOCGWINSZ) + + if err != nil { + return nil, err + } else { + return &Winsize{wsz.Row, wsz.Col, wsz.Xpixel, wsz.Ypixel}, nil + } +} + +// Get Windows Size +func Getsize(t *os.File) (rows, cols int, err error) { + var wsz *unix.Winsize + wsz, err = unix.IoctlGetWinsize(int(t.Fd()), TIOCGWINSZ) + + if err != nil { + return 80, 25, err + } else { + return int(wsz.Row), int(wsz.Col), nil + } +} + +// Setsize resizes t to s. +func Setsize(t *os.File, ws *Winsize) error { + wsz := unix.Winsize{ws.Rows, ws.Cols, ws.X, ws.Y} + return unix.IoctlSetWinsize(int(t.Fd()), TIOCSWINSZ, &wsz) +} diff --git a/vendor/github.com/elisescu/pty/ztypes_386.go b/vendor/github.com/creack/pty/ztypes_386.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_386.go rename to vendor/github.com/creack/pty/ztypes_386.go diff --git a/vendor/github.com/elisescu/pty/ztypes_amd64.go b/vendor/github.com/creack/pty/ztypes_amd64.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_amd64.go rename to vendor/github.com/creack/pty/ztypes_amd64.go diff --git a/vendor/github.com/elisescu/pty/ztypes_arm.go b/vendor/github.com/creack/pty/ztypes_arm.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_arm.go rename to vendor/github.com/creack/pty/ztypes_arm.go diff --git a/vendor/github.com/elisescu/pty/ztypes_arm64.go b/vendor/github.com/creack/pty/ztypes_arm64.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_arm64.go rename to vendor/github.com/creack/pty/ztypes_arm64.go diff --git a/vendor/github.com/elisescu/pty/ztypes_dragonfly_amd64.go b/vendor/github.com/creack/pty/ztypes_dragonfly_amd64.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_dragonfly_amd64.go rename to vendor/github.com/creack/pty/ztypes_dragonfly_amd64.go diff --git a/vendor/github.com/elisescu/pty/ztypes_freebsd_386.go b/vendor/github.com/creack/pty/ztypes_freebsd_386.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_freebsd_386.go rename to vendor/github.com/creack/pty/ztypes_freebsd_386.go diff --git a/vendor/github.com/elisescu/pty/ztypes_freebsd_amd64.go b/vendor/github.com/creack/pty/ztypes_freebsd_amd64.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_freebsd_amd64.go rename to vendor/github.com/creack/pty/ztypes_freebsd_amd64.go diff --git a/vendor/github.com/elisescu/pty/ztypes_freebsd_arm.go b/vendor/github.com/creack/pty/ztypes_freebsd_arm.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_freebsd_arm.go rename to vendor/github.com/creack/pty/ztypes_freebsd_arm.go diff --git a/vendor/github.com/creack/pty/ztypes_freebsd_arm64.go b/vendor/github.com/creack/pty/ztypes_freebsd_arm64.go new file mode 100644 index 0000000..4418139 --- /dev/null +++ b/vendor/github.com/creack/pty/ztypes_freebsd_arm64.go @@ -0,0 +1,13 @@ +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs types_freebsd.go + +package pty + +const ( + _C_SPECNAMELEN = 0xff +) + +type fiodgnameArg struct { + Len int32 + Buf *byte +} diff --git a/vendor/github.com/elisescu/pty/ztypes_mipsx.go b/vendor/github.com/creack/pty/ztypes_mipsx.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_mipsx.go rename to vendor/github.com/creack/pty/ztypes_mipsx.go diff --git a/vendor/github.com/creack/pty/ztypes_openbsd_32bit_int.go b/vendor/github.com/creack/pty/ztypes_openbsd_32bit_int.go new file mode 100644 index 0000000..d7cab4a --- /dev/null +++ b/vendor/github.com/creack/pty/ztypes_openbsd_32bit_int.go @@ -0,0 +1,13 @@ +// +build openbsd +// +build 386 amd64 arm arm64 + +package pty + +type ptmget struct { + Cfd int32 + Sfd int32 + Cn [16]int8 + Sn [16]int8 +} + +var ioctl_PTMGET = 0x40287401 diff --git a/vendor/github.com/elisescu/pty/ztypes_ppc64.go b/vendor/github.com/creack/pty/ztypes_ppc64.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_ppc64.go rename to vendor/github.com/creack/pty/ztypes_ppc64.go diff --git a/vendor/github.com/elisescu/pty/ztypes_ppc64le.go b/vendor/github.com/creack/pty/ztypes_ppc64le.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_ppc64le.go rename to vendor/github.com/creack/pty/ztypes_ppc64le.go diff --git a/vendor/github.com/creack/pty/ztypes_riscvx.go b/vendor/github.com/creack/pty/ztypes_riscvx.go new file mode 100644 index 0000000..99eec8e --- /dev/null +++ b/vendor/github.com/creack/pty/ztypes_riscvx.go @@ -0,0 +1,11 @@ +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs types.go + +// +build riscv riscv64 + +package pty + +type ( + _C_int int32 + _C_uint uint32 +) diff --git a/vendor/github.com/elisescu/pty/ztypes_s390x.go b/vendor/github.com/creack/pty/ztypes_s390x.go similarity index 100% rename from vendor/github.com/elisescu/pty/ztypes_s390x.go rename to vendor/github.com/creack/pty/ztypes_s390x.go diff --git a/vendor/github.com/elisescu/pty/README.md b/vendor/github.com/elisescu/pty/README.md deleted file mode 100644 index 7b7900c..0000000 --- a/vendor/github.com/elisescu/pty/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# pty - -Pty is a Go package for using unix pseudo-terminals. - -## Install - - go get github.com/kr/pty - -## Example - -```go -package main - -import ( - "github.com/kr/pty" - "io" - "os" - "os/exec" -) - -func main() { - c := exec.Command("grep", "--color=auto", "bar") - f, err := pty.Start(c) - if err != nil { - panic(err) - } - - go func() { - f.Write([]byte("foo\n")) - f.Write([]byte("bar\n")) - f.Write([]byte("baz\n")) - f.Write([]byte{4}) // EOT - }() - io.Copy(os.Stdout, f) -} -``` diff --git a/vendor/github.com/elisescu/pty/run.go b/vendor/github.com/elisescu/pty/run.go deleted file mode 100644 index baecca8..0000000 --- a/vendor/github.com/elisescu/pty/run.go +++ /dev/null @@ -1,34 +0,0 @@ -// +build !windows - -package pty - -import ( - "os" - "os/exec" - "syscall" -) - -// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, -// and c.Stderr, calls c.Start, and returns the File of the tty's -// corresponding pty. -func Start(c *exec.Cmd) (pty *os.File, err error) { - pty, tty, err := Open() - if err != nil { - return nil, err - } - defer tty.Close() - c.Stdout = tty - c.Stdin = tty - c.Stderr = tty - if c.SysProcAttr == nil { - c.SysProcAttr = &syscall.SysProcAttr{} - } - c.SysProcAttr.Setctty = true - c.SysProcAttr.Setsid = true - err = c.Start() - if err != nil { - pty.Close() - return nil, err - } - return pty, err -} diff --git a/vendor/github.com/elisescu/pty/util.go b/vendor/github.com/elisescu/pty/util.go deleted file mode 100644 index 4b3ac78..0000000 --- a/vendor/github.com/elisescu/pty/util.go +++ /dev/null @@ -1,64 +0,0 @@ -// +build !windows - -package pty - -import ( - "os" - "syscall" - "unsafe" -) - -// Getsize returns the number of rows (lines) and cols (positions -// in each line) in terminal t. -func Getsize(t *os.File) (rows, cols int, err error) { - var ws winsize - err = getwindowrect(&ws, t.Fd()) - return int(ws.ws_row), int(ws.ws_col), err -} - -// Setsize sets the number of rows (lines) and cols (positions -// in each line) in terminal t. Both rows and cols have to be -// positive integers. -func Setsize(t *os.File, rows, cols int) error { - ws := winsize{ - ws_col: uint16(cols), - ws_row: uint16(rows), - ws_xpixel: uint16(0), // not used - ws_ypixel: uint16(0), // not used - } - - return setwindowrect(&ws, t.Fd()) -} - -type winsize struct { - ws_row uint16 - ws_col uint16 - ws_xpixel uint16 - ws_ypixel uint16 -} - -func getwindowrect(ws *winsize, fd uintptr) error { - _, _, errno := syscall.Syscall( - syscall.SYS_IOCTL, - fd, - syscall.TIOCGWINSZ, - uintptr(unsafe.Pointer(ws)), - ) - if errno != 0 { - return syscall.Errno(errno) - } - return nil -} - -func setwindowrect(ws *winsize, fd uintptr) error { - _, _, errno := syscall.Syscall( - syscall.SYS_IOCTL, - fd, - syscall.TIOCSWINSZ, - uintptr(unsafe.Pointer(ws)), - ) - if errno != 0 { - return syscall.Errno(errno) - } - return nil -} diff --git a/vendor/modules.txt b/vendor/modules.txt index dfd421d..fd160ef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2,9 +2,9 @@ ## explicit; go 1.16 github.com/Azure/go-ansiterm github.com/Azure/go-ansiterm/winterm -# github.com/elisescu/pty v1.0.2 -## explicit -github.com/elisescu/pty +# github.com/creack/pty v1.1.11 +## explicit; go 1.13 +github.com/creack/pty # github.com/gorilla/mux v1.8.0 ## explicit; go 1.12 github.com/gorilla/mux