diff --git a/drivers/shared/executor/executor_basic.go b/drivers/shared/executor/executor_basic.go index e96cdcff7ed..b22183cf482 100644 --- a/drivers/shared/executor/executor_basic.go +++ b/drivers/shared/executor/executor_basic.go @@ -38,7 +38,7 @@ func withNetworkIsolation(f func() error, _ *drivers.NetworkIsolationSpec) error func setCmdUser(*exec.Cmd, string) error { return nil } func (e *UniversalExecutor) ListProcesses() set.Collection[int] { - return procstats.List(e.childCmd.Process.Pid) + return procstats.ListByPid(e.childCmd.Process.Pid) } func (e *UniversalExecutor) setSubCmdCgroup(*exec.Cmd, string) (func(), error) { diff --git a/drivers/shared/executor/executor_universal_linux.go b/drivers/shared/executor/executor_universal_linux.go index 3c113f6d0c5..576b6ced133 100644 --- a/drivers/shared/executor/executor_universal_linux.go +++ b/drivers/shared/executor/executor_universal_linux.go @@ -103,7 +103,13 @@ func (e *UniversalExecutor) setSubCmdCgroup(cmd *exec.Cmd, cgroup string) (func( } func (e *UniversalExecutor) ListProcesses() set.Collection[procstats.ProcessID] { - return procstats.List(e.command) + switch cgroupslib.GetMode() { + case cgroupslib.OFF: + // cgroup is unavailable, could possibly due to rootless nomad client + return procstats.ListByPid(e.childCmd.Process.Pid) + default: + return procstats.List(e.command) + } } func (e *UniversalExecutor) statCG(cgroup string) (int, func(), error) { diff --git a/drivers/shared/executor/procstats/list_default.go b/drivers/shared/executor/procstats/list_default.go index b6df7d386c5..0efd62bf06e 100644 --- a/drivers/shared/executor/procstats/list_default.go +++ b/drivers/shared/executor/procstats/list_default.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:build !linux && !windows +//go:build !windows package procstats @@ -15,7 +15,7 @@ import ( ) // List the process tree starting at the given executorPID -func List(executorPID int) set.Collection[ProcessID] { +func ListByPid(executorPID int) set.Collection[ProcessID] { result := set.New[ProcessID](10) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)