Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0132fb3

Browse files
committed
build files
1 parent05702c3 commit0132fb3

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+
funcCLI(args []string,environ []string)error {
9+
returnxerrors.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
funcCLI(args []string,environ []string)error {
2422
runtime.LockOSThread()
@@ -127,30 +125,3 @@ func oomScoreAdj(pid int) (int, error) {
127125
funcwriteOOMScoreAdj(pidint,scoreint)error {
128126
returnos.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-
funcenvValInt(env []string,keystring) (int,bool) {
134-
val,ok:=envVal(env,key)
135-
if!ok {
136-
return0,false
137-
}
138-
139-
i,err:=strconv.Atoi(val)
140-
iferr!=nil {
141-
return0,false
142-
}
143-
returni,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-
funcenvVal(env []string,keystring) (string,bool) {
149-
prefix:=key+"="
150-
for_,e:=rangeenv {
151-
ifstrings.HasPrefix(e,prefix) {
152-
returnstrings.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
returnexec.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+
funcenvValInt(env []string,keystring) (int,bool) {
51+
val,ok:=envVal(env,key)
52+
if!ok {
53+
return0,false
54+
}
55+
56+
i,err:=strconv.Atoi(val)
57+
iferr!=nil {
58+
return0,false
59+
}
60+
returni,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+
funcenvVal(env []string,keystring) (string,bool) {
66+
prefix:=key+"="
67+
for_,e:=rangeenv {
68+
ifstrings.HasPrefix(e,prefix) {
69+
returnstrings.TrimPrefix(e,prefix),true
70+
}
71+
}
72+
return"",false
73+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp