Merge pull request #4859 from hashicorp/b-rawexec-cgroups-root

rawexec: Only use cgroups when running as root.
This commit is contained in:
Danielle Tomlinson 2018-11-12 13:47:07 -08:00 committed by GitHub
commit 2f13e34888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,9 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"syscall"
"time"
"github.com/hashicorp/consul-template/signals"
@ -320,12 +322,16 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
return nil, nil, fmt.Errorf("failed to create executor: %v", err)
}
// Only use cgroups when running as root on linux - Doing so in other cases
// will cause an error.
useCgroups := !d.config.NoCgroups && runtime.GOOS == "linux" && syscall.Geteuid() == 0
execCmd := &executor.ExecCommand{
Cmd: driverConfig.Command,
Args: driverConfig.Args,
Env: cfg.EnvList(),
User: cfg.User,
BasicProcessCgroup: !d.config.NoCgroups,
BasicProcessCgroup: useCgroups,
TaskDir: cfg.TaskDir().Dir,
StdoutPath: cfg.StdoutPath,
StderrPath: cfg.StderrPath,