Skip to content

Commit a9bfb9a

Browse files
committed
Fix ptsname macOS implementation
See #79 Signed-off-by: Marat Radchenko <[email protected]>
1 parent 8f6c4e4 commit a9bfb9a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

console_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build linux || zos || freebsd
2-
// +build linux zos freebsd
1+
//go:build linux || zos || freebsd || darwin
2+
// +build linux zos freebsd darwin
33

44
/*
55
Copyright The containerd Authors.

tc_darwin.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
package console
1818

1919
import (
20-
"fmt"
20+
"bytes"
21+
"errors"
2122
"os"
23+
"syscall"
24+
"unsafe"
2225

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

3740
// ptsname retrieves the name of the first available pts for the given master.
3841
func ptsname(f *os.File) (string, error) {
39-
n, err := unix.IoctlGetInt(int(f.Fd()), unix.TIOCPTYGNAME)
40-
if err != nil {
41-
return "", err
42+
n := make([]byte, 128)
43+
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0]))); errno != 0 {
44+
return "", errno
4245
}
43-
return fmt.Sprintf("/dev/pts/%d", n), nil
46+
47+
end := bytes.IndexByte(n, 0)
48+
if end < 0 {
49+
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
50+
}
51+
52+
return string(n[:end]), nil
4453
}

0 commit comments

Comments
 (0)