ソースを参照

unix: add IoctlGetPtmget on netbsd

This ioctl is used to implement ptsname on netbsd.

Change-Id: Ic87f1bf7d15c6fbef0c2226a06a4983a504c3f30
Reviewed-on: https://go-review.googlesource.com/c/148097
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Tobias Klauser 7 年 前
コミット
66b7b1311a

+ 4 - 0
unix/mkpost.go

@@ -65,6 +65,10 @@ func main() {
 	convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
 	b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
 
+	// Convert [1024]int8 to [1024]byte in Ptmget members
+	convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
+	b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
+
 	// Remove spare fields (e.g. in Statx_t)
 	spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
 	b = spareFieldsRegex.ReplaceAll(b, []byte("_"))

+ 8 - 0
unix/syscall_netbsd.go

@@ -13,6 +13,7 @@
 package unix
 
 import (
+	"runtime"
 	"syscall"
 	"unsafe"
 )
@@ -190,6 +191,13 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
 	return &value, err
 }
 
+func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
+	var value Ptmget
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	runtime.KeepAlive(value)
+	return &value, err
+}
+
 func Uname(uname *Utsname) error {
 	mib := []_C_int{CTL_KERN, KERN_OSTYPE}
 	n := unsafe.Sizeof(uname.Sysname)

+ 16 - 0
unix/syscall_netbsd_test.go

@@ -5,6 +5,7 @@
 package unix_test
 
 import (
+	"bytes"
 	"testing"
 
 	"golang.org/x/sys/unix"
@@ -33,3 +34,18 @@ func TestSysctlClockinfo(t *testing.T) {
 	t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v",
 		ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz)
 }
+
+func TestIoctlPtmget(t *testing.T) {
+	fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
+	if err != nil {
+		t.Skip("failed to open /dev/ptmx, skipping test")
+	}
+	defer unix.Close(fd)
+
+	ptm, err := unix.IoctlGetPtmget(fd, unix.TIOCPTSNAME)
+	if err != nil {
+		t.Fatalf("IoctlGetPtmget: %v\n", err)
+	}
+
+	t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]))
+}

+ 2 - 0
unix/types_netbsd.go

@@ -248,6 +248,8 @@ type Termios C.struct_termios
 
 type Winsize C.struct_winsize
 
+type Ptmget C.struct_ptmget
+
 // fchmodat-like syscalls.
 
 const (

+ 7 - 0
unix/ztypes_netbsd_386.go

@@ -402,6 +402,13 @@ type Winsize struct {
 	Ypixel uint16
 }
 
+type Ptmget struct {
+	Cfd int32
+	Sfd int32
+	Cn  [1024]byte
+	Sn  [1024]byte
+}
+
 const (
 	AT_FDCWD            = -0x64
 	AT_SYMLINK_NOFOLLOW = 0x200

+ 7 - 0
unix/ztypes_netbsd_amd64.go

@@ -409,6 +409,13 @@ type Winsize struct {
 	Ypixel uint16
 }
 
+type Ptmget struct {
+	Cfd int32
+	Sfd int32
+	Cn  [1024]byte
+	Sn  [1024]byte
+}
+
 const (
 	AT_FDCWD            = -0x64
 	AT_SYMLINK_NOFOLLOW = 0x200

+ 7 - 0
unix/ztypes_netbsd_arm.go

@@ -407,6 +407,13 @@ type Winsize struct {
 	Ypixel uint16
 }
 
+type Ptmget struct {
+	Cfd int32
+	Sfd int32
+	Cn  [1024]byte
+	Sn  [1024]byte
+}
+
 const (
 	AT_FDCWD            = -0x64
 	AT_SYMLINK_NOFOLLOW = 0x200