From 1c41d8fafe7dd6e52ffe5c1d20e495875d908f0d Mon Sep 17 00:00:00 2001 From: Ivan Markin Date: Sun, 4 Mar 2018 16:58:11 +0000 Subject: [PATCH 1/2] Add OpenBSD support Signed-off-by: Ivan Markin --- console_unix.go | 2 +- tc_openbsd_cgo.go | 35 +++++++++++++++++++++++++++++++++++ tc_openbsd_nocgo.go | 31 +++++++++++++++++++++++++++++++ tc_unix.go | 2 +- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tc_openbsd_cgo.go create mode 100644 tc_openbsd_nocgo.go diff --git a/console_unix.go b/console_unix.go index 118c8c3..12e1a01 100644 --- a/console_unix.go +++ b/console_unix.go @@ -1,4 +1,4 @@ -// +build darwin freebsd linux solaris +// +build darwin freebsd linux openbsd solaris package console diff --git a/tc_openbsd_cgo.go b/tc_openbsd_cgo.go new file mode 100644 index 0000000..1310a66 --- /dev/null +++ b/tc_openbsd_cgo.go @@ -0,0 +1,35 @@ +// +build openbsd,cgo + +package console + +import ( + "os" + + "golang.org/x/sys/unix" +) + +//#include +import "C" + +const ( + cmdTcGet = unix.TIOCGETA + cmdTcSet = unix.TIOCSETA +) + +// ptsname retrieves the name of the first available pts for the given master. +func ptsname(f *os.File) (string, error) { + ptspath, err := C.ptsname(C.int(f.Fd())) + if err != nil { + return "", err + } + return C.GoString(ptspath), nil +} + +// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. +// unlockpt should be called before opening the slave side of a pty. +func unlockpt(f *os.File) error { + if _, err := C.grantpt(C.int(f.Fd())); err != nil { + return err + } + return nil +} diff --git a/tc_openbsd_nocgo.go b/tc_openbsd_nocgo.go new file mode 100644 index 0000000..b05849f --- /dev/null +++ b/tc_openbsd_nocgo.go @@ -0,0 +1,31 @@ +// +build openbsd,!cgo + +// +// Implementing the functions below requires cgo support. Non-cgo stubs +// versions are defined below to enable cross-compilation of source code +// that depends on these functions, but the resultant cross-compiled +// binaries cannot actually be used. If the stub function(s) below are +// actually invoked they will display an error message and cause the +// calling process to exit. +// + +package console + +import ( + "os" + + "golang.org/x/sys/unix" +) + +const ( + cmdTcGet = unix.TIOCGETA + cmdTcSet = unix.TIOCSETA +) + +func ptsname(f *os.File) (string, error) { + panic("ptsname() support requires cgo.") +} + +func unlockpt(f *os.File) error { + panic("unlockpt() support requires cgo.") +} diff --git a/tc_unix.go b/tc_unix.go index df7dcb9..b8b1d49 100644 --- a/tc_unix.go +++ b/tc_unix.go @@ -1,4 +1,4 @@ -// +build darwin freebsd linux solaris +// +build darwin freebsd linux openbsd solaris package console From f3c72f0cb615d0d53451de17af2f0c2662df0e78 Mon Sep 17 00:00:00 2001 From: Ivan Markin Date: Mon, 5 Mar 2018 19:47:11 +0000 Subject: [PATCH 2/2] Add OpenBSD to TravisCI Signed-off-by: Ivan Markin --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e2b0084..db8698a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,14 +8,17 @@ go_import_path: github.com/containerd/console install: - go get -d - - GOOS=windows go get -d + - GOOS=openbsd go get -d - GOOS=solaris go get -d + - GOOS=windows go get -d script: - go test -race - - GOOS=windows go test + - GOOS=openbsd go build + - GOOS=openbsd go test -c - GOOS=solaris go build - GOOS=solaris go test -c + - GOOS=windows go test matrix: allow_failures: