Skip to content

Commit 0132fb3

Browse files
committed
build files
1 parent 05702c3 commit 0132fb3

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

agent/agentexec/cli_other.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !linux
2+
// +build !linux
3+
4+
package agentexec
5+
6+
import "golang.org/x/xerrors"
7+
8+
func CLI(args []string, environ []string) error {
9+
return xerrors.Errorf("agent-exec is only supported on Linux")
10+
}

agent/agentexec/cli.go renamed to agent/agentexec/cli_unix.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build linux
2+
// +build linux
3+
14
package agentexec
25

36
import (
@@ -14,11 +17,6 @@ import (
1417
"golang.org/x/xerrors"
1518
)
1619

17-
const (
18-
EnvProcOOMScore = "CODER_PROC_OOM_SCORE"
19-
EnvProcNiceScore = "CODER_PROC_NICE_SCORE"
20-
)
21-
2220
// CLI runs the agent-exec command. It should only be called by the cli package.
2321
func CLI(args []string, environ []string) error {
2422
runtime.LockOSThread()
@@ -127,30 +125,3 @@ func oomScoreAdj(pid int) (int, error) {
127125
func writeOOMScoreAdj(pid int, score int) error {
128126
return os.WriteFile(fmt.Sprintf("/proc/%d/oom_score_adj", pid), []byte(fmt.Sprintf("%d", score)), 0o600)
129127
}
130-
131-
// envValInt searches for a key in a list of environment variables and parses it to an int.
132-
// If the key is not found or cannot be parsed, returns 0 and false.
133-
func envValInt(env []string, key string) (int, bool) {
134-
val, ok := envVal(env, key)
135-
if !ok {
136-
return 0, false
137-
}
138-
139-
i, err := strconv.Atoi(val)
140-
if err != nil {
141-
return 0, false
142-
}
143-
return i, true
144-
}
145-
146-
// envVal searches for a key in a list of environment variables and returns its value.
147-
// If the key is not found, returns empty string and false.
148-
func envVal(env []string, key string) (string, bool) {
149-
prefix := key + "="
150-
for _, e := range env {
151-
if strings.HasPrefix(e, prefix) {
152-
return strings.TrimPrefix(e, prefix), true
153-
}
154-
}
155-
return "", false
156-
}

agent/agentexec/exec.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import (
66
"os/exec"
77
"path/filepath"
88
"runtime"
9+
"strconv"
10+
"strings"
911

1012
"golang.org/x/xerrors"
1113
)
1214

1315
const (
1416
// EnvProcPrioMgmt is the environment variable that determines whether
1517
// we attempt to manage process CPU and OOM Killer priority.
16-
EnvProcPrioMgmt = "CODER_PROC_PRIO_MGMT"
18+
EnvProcPrioMgmt = "CODER_PROC_PRIO_MGMT"
19+
EnvProcOOMScore = "CODER_PROC_OOM_SCORE"
20+
EnvProcNiceScore = "CODER_PROC_NICE_SCORE"
1721
)
1822

1923
// CommandContext returns an exec.Cmd that calls "coder agent-exec" prior to exec'ing
@@ -40,3 +44,30 @@ func CommandContext(ctx context.Context, cmd string, args ...string) (*exec.Cmd,
4044
args = append([]string{"agent-exec", cmd}, args...)
4145
return exec.CommandContext(ctx, bin, args...), nil
4246
}
47+
48+
// envValInt searches for a key in a list of environment variables and parses it to an int.
49+
// If the key is not found or cannot be parsed, returns 0 and false.
50+
func envValInt(env []string, key string) (int, bool) {
51+
val, ok := envVal(env, key)
52+
if !ok {
53+
return 0, false
54+
}
55+
56+
i, err := strconv.Atoi(val)
57+
if err != nil {
58+
return 0, false
59+
}
60+
return i, true
61+
}
62+
63+
// envVal searches for a key in a list of environment variables and returns its value.
64+
// If the key is not found, returns empty string and false.
65+
func envVal(env []string, key string) (string, bool) {
66+
prefix := key + "="
67+
for _, e := range env {
68+
if strings.HasPrefix(e, prefix) {
69+
return strings.TrimPrefix(e, prefix), true
70+
}
71+
}
72+
return "", false
73+
}

0 commit comments

Comments
 (0)