Skip to content

Commit

Permalink
func: comment out subreaper asignation
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanadelacuesta committed May 1, 2024
1 parent cc67ba5 commit aaea742
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/lib/cgroupslib/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
root = "/sys/fs/cgroup"
)

func GetNomadCGRoot() string {
func GetDefautlRoot() string {
return root
}

Expand Down
11 changes: 0 additions & 11 deletions drivers/exec/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/hashicorp/nomad/plugins/drivers/utils"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
pstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"golang.org/x/sys/unix"
)

const (
Expand Down Expand Up @@ -424,13 +423,6 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
return nil
}

func (d *Driver) SetAsSubreaper() {
d.logger.Info(" setting nomad as subreaper")
if err := unix.Prctl(unix.PR_SET_CHILD_SUBREAPER, uintptr(1), 0, 0, 0); err != nil {
d.logger.Error("unable to set as subreaper", err)
}
}

func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drivers.DriverNetwork, error) {
if _, ok := d.tasks.Get(cfg.ID); ok {
return nil, nil, fmt.Errorf("task with ID %q already started", cfg.ID)
Expand Down Expand Up @@ -504,8 +496,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
Capabilities: caps,
}

d.SetAsSubreaper()

ps, err := exec.Launch(execCmd)
if err != nil {
pluginClient.Kill()
Expand Down Expand Up @@ -595,7 +585,6 @@ func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) e
}

func (d *Driver) DestroyTask(taskID string, force bool) error {

handle, ok := d.tasks.Get(taskID)
if !ok {
return drivers.ErrTaskNotFound
Expand Down
2 changes: 1 addition & 1 deletion drivers/shared/executor/executor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (l *LibcontainerExecutor) ListProcesses() *set.Set[int] {
// killOrphans kills processes that ended up reparented to Nomad when the
// executor was unexpectedly killed.
func (l *LibcontainerExecutor) killOrphans(nomadRelativePath string) {
root := cgroupslib.GetNomadCGRoot()
root := cgroupslib.GetDefautlRoot()
orphansPIDs, err := cgroups.GetAllPids(filepath.Join(root, nomadRelativePath))
if err != nil {
l.logger.Error("unable to get orphan allocs PIDs", err)
Expand Down
4 changes: 4 additions & 0 deletions drivers/shared/executor/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func CreateExecutor(
isolateCommand(config.Cmd)
}

/* if err := setAsSubreaper(); err != nil {
return nil, nil, fmt.Errorf("unable to set nomad as subreaper: %v", err)
} */

return newExecutorClient(config, logger)
}

Expand Down
6 changes: 6 additions & 0 deletions drivers/shared/executor/utils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package executor
import (
"os/exec"
"syscall"

"golang.org/x/sys/unix"
)

// isolateCommand sets the setsid flag in exec.Cmd to true so that the process
Expand All @@ -20,3 +22,7 @@ func isolateCommand(cmd *exec.Cmd) {
}
cmd.SysProcAttr.Setsid = true
}

func setAsSubreaper() error {
return unix.Prctl(unix.PR_SET_CHILD_SUBREAPER, uintptr(1), 0, 0, 0)
}

0 comments on commit aaea742

Please sign in to comment.