Skip to content

Commit

Permalink
Merge pull request #3380 from oasisprotocol/tjanez/stable/20.11.x/bac…
Browse files Browse the repository at this point in the history
…kport-macos-fix

[BACKPORT/20.11.x] go: Update to build on macOS
  • Loading branch information
tjanez authored Oct 6, 2020
2 parents 9761685 + a959f79 commit 78ae4e6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .changelog/3333.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go: Update to build on macOS
6 changes: 2 additions & 4 deletions go/common/crypto/signature/signers/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"net/rpc"
"os/exec"
"sync"
"syscall"

hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"

"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/syscall"
)

const (
Expand Down Expand Up @@ -94,9 +94,7 @@ func NewFactory(config interface{}, roles ...signature.SignerRole) (signature.Si
// We do use managed plugins so that in the graceful exit case,
// the cleanup will be done at least.
cmd := exec.Command(cfg.Path) // nolint: gosec
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
cmd.SysProcAttr = syscall.CmdAttrs

client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: handshakeConfigForName(cfg.Name),
Expand Down
12 changes: 12 additions & 0 deletions go/common/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package syscall defines OS-specific syscall parameters.
package syscall

import "syscall"

// IoctlTermiosGetAttr is the ioctl that implements termios tcgetattr.
const IoctlTermiosGetAttr = syscall.TIOCGETA

// CmdAttrs is the SysProcAttr used for spawning child processes. It is empty
// for Darwin as PR_SET_PDEATH_SIG is not implemented. As a consequence, child
// processes may not be cleaned up.
var CmdAttrs = &syscall.SysProcAttr{}
12 changes: 12 additions & 0 deletions go/common/syscall/syscall_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package syscall defines OS-specific syscall parameters.
package syscall

import "syscall"

// IoctlTermiosGetAttr is the ioctl that implements termios tcgetattr.
const IoctlTermiosGetAttr = syscall.TCGETS

// CmdAttrs is the SysProcAttr that will ensure graceful cleanup (on Linux).
var CmdAttrs = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
4 changes: 3 additions & 1 deletion go/oasis-node/cmd/common/isatty.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package common
import (
"syscall"
"unsafe"

cmnSyscall "github.com/oasisprotocol/oasis-core/go/common/syscall"
)

// Isatty returns true iff the provided file descriptor is a terminal.
Expand All @@ -20,7 +22,7 @@ func Isatty(fd uintptr) bool {
_, _, errno := syscall.Syscall6(
syscall.SYS_IOCTL,
fd,
syscall.TCGETS,
cmnSyscall.IoctlTermiosGetAttr,
uintptr(unsafe.Pointer(&attrs)),
0,
0,
Expand Down
8 changes: 4 additions & 4 deletions go/oasis-test-runner/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (
"time"

flag "github.com/spf13/pflag"

cmnSyscall "github.com/oasisprotocol/oasis-core/go/common/syscall"
)

// ErrEarlyTerm is the error passed over the error channel when a
// sub-process terminates prior to the Cleanup.
var ErrEarlyTerm = errors.New("env: sub-process exited early")

// CmdAttrs is the SysProcAttr that will ensure graceful cleanup.
var CmdAttrs = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
// CmdAttrs is the SysProcAttr that will ensure graceful cleanup (on Linux).
var CmdAttrs = cmnSyscall.CmdAttrs

// CleanupFn is the cleanup hook function prototype.
type CleanupFn func()
Expand Down

0 comments on commit 78ae4e6

Please sign in to comment.