@@ -1676,16 +1676,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16761676}
16771677
16781678score ,niceErr := proc .Niceness (a .syscaller )
1679- if niceErr != 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
17001696if niceErr == nil {
17011697err := proc .SetNiceness (a .syscaller ,niceness )
1702- if err != 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.
17151709if oomScore != unsetOOMScore && oomScore != proc .OOMScoreAdj && ! isCustomOOMScore (agentScore ,proc ) {
17161710oomScoreStr := strconv .Itoa (oomScore )
17171711err := afero .WriteFile (a .filesystem ,fmt .Sprintf ("/proc/%d/oom_score_adj" ,proc .PID ), []byte (oomScoreStr ),0o644 )
1718- if err != 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}
17291721modProcs = append (modProcs ,proc )
@@ -2154,6 +2146,13 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21542146l .messages [msg ]= time .Now ()
21552147}
21562148
2149+ func isBenignProcessErr (err error )bool {
2150+ return err != nil &&
2151+ (xerrors .Is (err ,os .ErrNotExist )||
2152+ xerrors .Is (err ,os .ErrPermission )||
2153+ isNoSuchProcessErr (err ))
2154+ }
2155+
21572156func isNoSuchProcessErr (err error )bool {
21582157return err != nil && strings .Contains (err .Error (),"no such process" )
21592158}