Add a helper functions for checking unix root
This commit is contained in:
parent
21d126cd68
commit
032f86bc78
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/hashicorp/nomad/plugins/shared/hclspec"
|
||||
"github.com/hashicorp/nomad/plugins/shared/loader"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -207,7 +206,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
|
|||
return fp
|
||||
}
|
||||
|
||||
if unix.Geteuid() != 0 {
|
||||
if !utils.IsUnixRoot() {
|
||||
fp.Health = drivers.HealthStateUnhealthy
|
||||
fp.HealthDescription = "exec driver must run as root"
|
||||
return fp
|
||||
|
|
|
@ -5,6 +5,8 @@ package utils
|
|||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// isolateCommand sets the setsid flag in exec.Cmd to true so that the process
|
||||
|
@ -16,3 +18,8 @@ func isolateCommand(cmd *exec.Cmd) {
|
|||
}
|
||||
cmd.SysProcAttr.Setsid = true
|
||||
}
|
||||
|
||||
// IsUnixRoot returns true if system is unix and user running is effectively root
|
||||
func IsUnixRoot() bool {
|
||||
return unix.Geteuid() == 0
|
||||
}
|
||||
|
|
|
@ -6,3 +6,8 @@ import (
|
|||
|
||||
// TODO Figure out if this is needed in Windows
|
||||
func isolateCommand(cmd *exec.Cmd) {}
|
||||
|
||||
// IsUnixRoot returns true if system is a unix system and the effective uid of user is root
|
||||
func IsUnixRoot() bool {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue