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

Commitbfdc29f

Browse files
authored
fix: suppress benign errors when listing processes (#14660)
1 parentbf87c97 commitbfdc29f

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

‎agent/agent.go

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,16 +1676,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16761676
}
16771677

16781678
score,niceErr:=proc.Niceness(a.syscaller)
1679-
ifniceErr!=nil&&!xerrors.Is(niceErr,os.ErrPermission) {
1680-
if!isNoSuchProcessErr(niceErr) {
1681-
debouncer.Warn(ctx,"unable to get proc niceness",
1682-
slog.F("cmd",proc.Cmd()),
1683-
slog.F("pid",proc.PID),
1684-
slog.Error(niceErr),
1685-
)
1686-
}
1687-
1688-
continue
1679+
if!isBenignProcessErr(niceErr) {
1680+
debouncer.Warn(ctx,"unable to get proc niceness",
1681+
slog.F("cmd",proc.Cmd()),
1682+
slog.F("pid",proc.PID),
1683+
slog.Error(niceErr),
1684+
)
16891685
}
16901686

16911687
// We only want processes that don't have a nice value set
@@ -1699,31 +1695,27 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16991695

17001696
ifniceErr==nil {
17011697
err:=proc.SetNiceness(a.syscaller,niceness)
1702-
iferr!=nil&&!xerrors.Is(err,os.ErrPermission) {
1703-
if!isNoSuchProcessErr(err) {
1704-
debouncer.Warn(ctx,"unable to set proc niceness",
1705-
slog.F("cmd",proc.Cmd()),
1706-
slog.F("pid",proc.PID),
1707-
slog.F("niceness",niceness),
1708-
slog.Error(err),
1709-
)
1710-
}
1698+
if!isBenignProcessErr(err) {
1699+
debouncer.Warn(ctx,"unable to set proc niceness",
1700+
slog.F("cmd",proc.Cmd()),
1701+
slog.F("pid",proc.PID),
1702+
slog.F("niceness",niceness),
1703+
slog.Error(err),
1704+
)
17111705
}
17121706
}
17131707

17141708
// If the oom score is valid and it's not already set and isn't a custom value set by another process then it's ok to update it.
17151709
ifoomScore!=unsetOOMScore&&oomScore!=proc.OOMScoreAdj&&!isCustomOOMScore(agentScore,proc) {
17161710
oomScoreStr:=strconv.Itoa(oomScore)
17171711
err:=afero.WriteFile(a.filesystem,fmt.Sprintf("/proc/%d/oom_score_adj",proc.PID), []byte(oomScoreStr),0o644)
1718-
iferr!=nil&&!xerrors.Is(err,os.ErrPermission) {
1719-
if!isNoSuchProcessErr(err) {
1720-
debouncer.Warn(ctx,"unable to set oom_score_adj",
1721-
slog.F("cmd",proc.Cmd()),
1722-
slog.F("pid",proc.PID),
1723-
slog.F("score",oomScoreStr),
1724-
slog.Error(err),
1725-
)
1726-
}
1712+
if!isBenignProcessErr(err) {
1713+
debouncer.Warn(ctx,"unable to set oom_score_adj",
1714+
slog.F("cmd",proc.Cmd()),
1715+
slog.F("pid",proc.PID),
1716+
slog.F("score",oomScoreStr),
1717+
slog.Error(err),
1718+
)
17271719
}
17281720
}
17291721
modProcs=append(modProcs,proc)
@@ -2154,6 +2146,13 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21542146
l.messages[msg]=time.Now()
21552147
}
21562148

2149+
funcisBenignProcessErr(errerror)bool {
2150+
returnerr!=nil&&
2151+
(xerrors.Is(err,os.ErrNotExist)||
2152+
xerrors.Is(err,os.ErrPermission)||
2153+
isNoSuchProcessErr(err))
2154+
}
2155+
21572156
funcisNoSuchProcessErr(errerror)bool {
21582157
returnerr!=nil&&strings.Contains(err.Error(),"no such process")
21592158
}

‎agent/agentproc/proc_unix.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ func List(fs afero.Fs, syscaller Syscaller) ([]*Process, error) {
4545

4646
cmdline,err:=afero.ReadFile(fs,filepath.Join(defaultProcDir,entry,"cmdline"))
4747
iferr!=nil {
48-
varerrNo syscall.Errno
49-
ifxerrors.As(err,&errNo)&&errNo==syscall.EPERM {
48+
ifisBenignError(err) {
5049
continue
5150
}
5251
returnnil,xerrors.Errorf("read cmdline: %w",err)
5352
}
5453

5554
oomScore,err:=afero.ReadFile(fs,filepath.Join(defaultProcDir,entry,"oom_score_adj"))
5655
iferr!=nil {
57-
ifxerrors.Is(err,os.ErrPermission) {
56+
ifisBenignError(err) {
5857
continue
5958
}
6059

@@ -124,3 +123,12 @@ func (p *Process) Cmd() string {
124123
func (p*Process)cmdLine() []string {
125124
returnstrings.Split(p.CmdLine,"\x00")
126125
}
126+
127+
funcisBenignError(errerror)bool {
128+
varerrno syscall.Errno
129+
if!xerrors.As(err,&errno) {
130+
returnfalse
131+
}
132+
133+
returnerrno==syscall.ESRCH||errno==syscall.EPERM||xerrors.Is(err,os.ErrNotExist)
134+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp