Prefer `golang.org/x/sys/unix` where appropriate

Favor the `unix` package on *NIX platforms vs the now frozen `syscall` package.
This commit is contained in:
Sean Chittenden 2016-05-07 10:43:02 -07:00
parent 1314227863
commit 09f7d5e595
4 changed files with 35 additions and 30 deletions

View File

@ -8,7 +8,8 @@ import (
"os"
"os/user"
"strconv"
"syscall"
"golang.org/x/sys/unix"
)
func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error {
@ -22,7 +23,7 @@ func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error {
func (d *AllocDir) dropDirPermissions(path string) error {
// Can't do anything if not root.
if syscall.Geteuid() != 0 {
if unix.Geteuid() != 0 {
return nil
}

View File

@ -7,9 +7,10 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"time"
"golang.org/x/sys/unix"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/client/allocdir"
@ -93,7 +94,7 @@ func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
}
delete(node.Attributes, execDriverAttr)
return false, nil
} else if syscall.Geteuid() != 0 {
} else if unix.Geteuid() != 0 {
if currentlyEnabled {
d.logger.Printf("[DEBUG] driver.exec: must run as root user, disabling")
}

View File

@ -11,7 +11,6 @@ import (
"runtime"
"strings"
"sync"
"syscall"
"time"
"github.com/hashicorp/go-multierror"
@ -324,31 +323,6 @@ func (e *UniversalExecutor) UpdateTask(task *structs.Task) error {
return nil
}
func (e *UniversalExecutor) wait() {
defer close(e.processExited)
err := e.cmd.Wait()
ic := &cstructs.IsolationConfig{Cgroup: e.groups, CgroupPaths: e.cgPaths}
if err == nil {
e.exitState = &ProcessState{Pid: 0, ExitCode: 0, IsolationConfig: ic, Time: time.Now()}
return
}
exitCode := 1
var signal int
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
exitCode = status.ExitStatus()
if status.Signaled() {
signal = int(status.Signal())
exitCode = 128 + signal
}
}
} else {
e.logger.Printf("[DEBUG] executor: unexpected Wait() error type: %v", err)
}
e.exitState = &ProcessState{Pid: 0, ExitCode: exitCode, Signal: signal, IsolationConfig: ic, Time: time.Now()}
}
var (
// finishedErr is the error message received when trying to kill and already
// exited process.

View File

@ -6,6 +6,10 @@ import (
"fmt"
"io"
"log/syslog"
"os/exec"
"time"
"golang.org/x/sys/unix"
"github.com/hashicorp/nomad/client/driver/logging"
)
@ -48,3 +52,28 @@ func (e *UniversalExecutor) collectLogs(we io.Writer, wo io.Writer) {
}
}
}
func (e *UniversalExecutor) wait() {
defer close(e.processExited)
err := e.cmd.Wait()
ic := &cstructs.IsolationConfig{Cgroup: e.groups, CgroupPaths: e.cgPaths}
if err == nil {
e.exitState = &ProcessState{Pid: 0, ExitCode: 0, IsolationConfig: ic, Time: time.Now()}
return
}
exitCode := 1
var signal int
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(unix.WaitStatus); ok {
exitCode = status.ExitStatus()
if status.Signaled() {
signal = int(status.Signal())
exitCode = 128 + signal
}
}
} else {
e.logger.Printf("[DEBUG] executor: unexpected Wait() error type: %v", err)
}
e.exitState = &ProcessState{Pid: 0, ExitCode: exitCode, Signal: signal, IsolationConfig: ic, Time: time.Now()}
}