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

Commit5076cf0

Browse files
committed
pr changes
1 parent471ea8d commit5076cf0

File tree

6 files changed

+55
-40
lines changed

6 files changed

+55
-40
lines changed

‎agent/agentexec/cli_unix.go‎renamed to ‎agent/agentexec/cli_linux.go‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func CLI() error {
2525
// We lock the OS thread here to avoid a race conditino where the nice priority
2626
// we get is on a different thread from the one we set it on.
2727
runtime.LockOSThread()
28+
// Nop on success but we do it anyway in case of an error.
29+
deferruntime.UnlockOSThread()
2830

2931
var (
3032
fs=flag.NewFlagSet("agent-exec",flag.ExitOnError)
@@ -42,18 +44,12 @@ func CLI() error {
4244
returnxerrors.Errorf("parse flags: %w",err)
4345
}
4446

45-
ifruntime.GOOS!="linux" {
46-
returnxerrors.Errorf("agent-exec is only supported on Linux")
47-
}
48-
4947
// Get everything after "coder agent-exec --"
5048
args:=execArgs(os.Args)
5149
iflen(args)==0 {
5250
returnxerrors.Errorf("no exec command provided %+v",os.Args)
5351
}
5452

55-
pid:=os.Getpid()
56-
5753
if*nice==unset {
5854
// If an explicit nice score isn't set, we use the default.
5955
*nice,err=defaultNiceScore()
@@ -75,7 +71,7 @@ func CLI() error {
7571
returnxerrors.Errorf("set nice score: %w",err)
7672
}
7773

78-
err=writeOOMScoreAdj(pid,*oom)
74+
err=writeOOMScoreAdj(*oom)
7975
iferr!=nil {
8076
returnxerrors.Errorf("set oom score: %w",err)
8177
}
@@ -104,7 +100,7 @@ func defaultNiceScore() (int, error) {
104100
}
105101

106102
funcdefaultOOMScore() (int,error) {
107-
score,err:=oomScoreAdj(os.Getpid())
103+
score,err:=oomScoreAdj()
108104
iferr!=nil {
109105
return0,xerrors.Errorf("get oom score: %w",err)
110106
}
@@ -126,16 +122,16 @@ func defaultOOMScore() (int, error) {
126122
return998,nil
127123
}
128124

129-
funcoomScoreAdj(pidint) (int,error) {
130-
scoreStr,err:=os.ReadFile(fmt.Sprintf("/proc/%d/oom_score_adj",pid))
125+
funcoomScoreAdj() (int,error) {
126+
scoreStr,err:=os.ReadFile("/proc/self/oom_score_adj")
131127
iferr!=nil {
132128
return0,xerrors.Errorf("read oom_score_adj: %w",err)
133129
}
134130
returnstrconv.Atoi(strings.TrimSpace(string(scoreStr)))
135131
}
136132

137-
funcwriteOOMScoreAdj(pidint,scoreint)error {
138-
returnos.WriteFile(fmt.Sprintf("/proc/%d/oom_score_adj",pid), []byte(fmt.Sprintf("%d",score)),0o600)
133+
funcwriteOOMScoreAdj(scoreint)error {
134+
returnos.WriteFile("/proc/self/oom_score_adj", []byte(fmt.Sprintf("%d",score)),0o600)
139135
}
140136

141137
// execArgs returns the arguments to pass to syscall.Exec after the "--" delimiter.
File renamed without changes.

‎agent/agentexec/cli_other.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ package agentexec
66
import"golang.org/x/xerrors"
77

88
funcCLI()error {
9-
returnxerrors.Errorf("agent-exec is only supported on Linux")
9+
returnxerrors.New("agent-exec is only supported on Linux")
1010
}

‎agent/agentexec/cmdtest/main.go‎renamed to ‎agent/agentexec/cmdtest/main_linux.go‎

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

36
import (

‎agent/agentexec/main_linux_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package agentexec_test
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
"testing"
9+
)
10+
11+
varTestBinstring
12+
13+
funcTestMain(m*testing.M) {
14+
code:=func()int {
15+
// We generate a unique directory per test invocation to avoid collisions between two
16+
// processes attempting to create the same temp file.
17+
dir:=genDir()
18+
deferos.RemoveAll(dir)
19+
TestBin=buildBinary(dir)
20+
returnm.Run()
21+
}()
22+
23+
os.Exit(code)
24+
}
25+
26+
funcbuildBinary(dirstring)string {
27+
path:=filepath.Join(dir,"agent-test")
28+
out,err:=exec.Command("go","build","-o",path,"./cmdtest").CombinedOutput()
29+
mustf(err,"build binary: %s",out)
30+
returnpath
31+
}
32+
33+
funcmustf(errerror,msgstring,args...any) {
34+
iferr!=nil {
35+
panic(fmt.Sprintf(msg,args...))
36+
}
37+
}
38+
39+
funcgenDir()string {
40+
dir,err:=os.MkdirTemp(os.TempDir(),"agentexec")
41+
mustf(err,"create temp dir: %v",err)
42+
returndir
43+
}

‎agent/agentexec/main_test.go‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp