Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions console_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux || zos || freebsd
// +build linux zos freebsd
//go:build linux || zos || freebsd || darwin
// +build linux zos freebsd darwin

/*
Copyright The containerd Authors.
Expand Down
19 changes: 14 additions & 5 deletions tc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package console

import (
"fmt"
"bytes"
"errors"
"os"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
)
Expand All @@ -36,9 +39,15 @@ func unlockpt(f *os.File) error {

// ptsname retrieves the name of the first available pts for the given master.
func ptsname(f *os.File) (string, error) {
n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCPTYGNAME)
if err != nil {
return "", err
n := make([]byte, 128)
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0]))); errno != 0 {
return "", errno
}
return fmt.Sprintf("/dev/pts/%d", n), nil

end := bytes.IndexByte(n, 0)
if end < 0 {
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
}

return string(n[:end]), nil
}