Skip to content

Commit

Permalink
Merge pull request #21 from nogoegst/openbsd-support
Browse files Browse the repository at this point in the history
Add OpenBSD support
  • Loading branch information
estesp committed Mar 5, 2018
2 parents 2748ece + f3c72f0 commit 45c0279
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
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

0 comments on commit 45c0279

Please sign in to comment.