fix: filter agent-exec env vars (#15764)

- Filters env vars specific to agent-exec from the exec'd process. This
is to prevent any issues when developing Coder in Coder, particularly
agent tests in the cli pkg.
This commit is contained in:
Jon Ayers
2024-12-05 16:33:27 +00:00
committed by GitHub
parent f8d938d299
commit 354d0fc4c8
2 changed files with 48 additions and 1 deletions
+11 -1
View File
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"runtime"
"slices"
"strconv"
"strings"
"syscall"
@@ -111,7 +112,16 @@ func CLI() error {
return xerrors.Errorf("look path: %w", err)
}
return syscall.Exec(path, args, os.Environ())
// Remove environment variables specific to the agentexec command. This is
// especially important for environments that are attempting to develop Coder in Coder.
env := os.Environ()
env = slices.DeleteFunc(env, func(e string) bool {
return strings.HasPrefix(e, EnvProcPrioMgmt) ||
strings.HasPrefix(e, EnvProcOOMScore) ||
strings.HasPrefix(e, EnvProcNiceScore)
})
return syscall.Exec(path, args, env)
}
func defaultNiceScore() (int, error) {