Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenBSD support #21

Merged
merged 2 commits into from
Mar 5, 2018
Merged
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
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion console_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd linux solaris
// +build darwin freebsd linux openbsd solaris

package console

Expand Down
35 changes: 35 additions & 0 deletions tc_openbsd_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// +build openbsd,cgo

package console

import (
"os"

"golang.org/x/sys/unix"
)

//#include <stdlib.h>
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
}
31 changes: 31 additions & 0 deletions tc_openbsd_nocgo.go
Original file line number Diff line number Diff line change
@@ -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.")
}
2 changes: 1 addition & 1 deletion tc_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin freebsd linux solaris
// +build darwin freebsd linux openbsd solaris

package console

Expand Down