Skip to content

Commit

Permalink
Merge pull request #855 from hashicorp/cgroups-pid
Browse files Browse the repository at this point in the history
Updated logic for creation of cgroup
  • Loading branch information
diptanu committed Mar 2, 2016
2 parents dbd815b + 71fb58c commit 75bedf8
Show file tree
Hide file tree
Showing 220 changed files with 527 additions and 25,655 deletions.
260 changes: 190 additions & 70 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion client/driver/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func (e *UniversalExecutor) applyLimits(pid int) error {
func (e *UniversalExecutor) configureCgroups(resources *structs.Resources) error {
e.groups = &cgroupConfig.Cgroup{}
e.groups.Resources = &cgroupConfig.Resources{}
e.groups.Name = structs.GenerateUUID()
cgroupName := structs.GenerateUUID()
cgPath, err := cgroups.GetThisCgroupDir("devices")
if err != nil {
return fmt.Errorf("unable to get mount point for devices sub-system: %v", err)
}
e.groups.Path = filepath.Join(cgPath, cgroupName)

// TODO: verify this is needed for things like network access
e.groups.Resources.AllowAllDevices = true
Expand Down Expand Up @@ -191,6 +196,12 @@ func DestroyCgroup(groups *cgroupConfig.Cgroup) error {
manager := getCgroupManager(groups)
if pids, perr := manager.GetPids(); perr == nil {
for _, pid := range pids {
// If the pid is the pid of the executor then we don't kill it, the
// executor is going to be killed by the driver once the Wait
// returns
if pid == os.Getpid() {
continue
}
proc, err := os.FindProcess(pid)
if err != nil {
merrs.Errors = append(merrs.Errors, fmt.Errorf("error finding process %v: %v", pid, err))
Expand All @@ -200,6 +211,8 @@ func DestroyCgroup(groups *cgroupConfig.Cgroup) error {
}
}
}
} else {
merrs.Errors = append(merrs.Errors, fmt.Errorf("error getting pids: %v", perr))
}

// Remove the cgroup.
Expand Down
Loading

0 comments on commit 75bedf8

Please sign in to comment.