@@ -1669,16 +1669,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1669
1669
}
1670
1670
1671
1671
score , niceErr := proc .Niceness (a .syscaller )
1672
- if niceErr != nil && ! xerrors .Is (niceErr , os .ErrPermission ) {
1673
- if ! isNoSuchProcessErr (niceErr ) {
1674
- debouncer .Warn (ctx , "unable to get proc niceness" ,
1675
- slog .F ("cmd" , proc .Cmd ()),
1676
- slog .F ("pid" , proc .PID ),
1677
- slog .Error (niceErr ),
1678
- )
1679
- }
1680
-
1681
- continue
1672
+ if ! isBenignProcessErr (niceErr ) {
1673
+ debouncer .Warn (ctx , "unable to get proc niceness" ,
1674
+ slog .F ("cmd" , proc .Cmd ()),
1675
+ slog .F ("pid" , proc .PID ),
1676
+ slog .Error (niceErr ),
1677
+ )
1682
1678
}
1683
1679
1684
1680
// We only want processes that don't have a nice value set
@@ -1692,31 +1688,27 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1692
1688
1693
1689
if niceErr == nil {
1694
1690
err := proc .SetNiceness (a .syscaller , niceness )
1695
- if err != nil && ! xerrors .Is (err , os .ErrPermission ) {
1696
- if ! isNoSuchProcessErr (err ) {
1697
- debouncer .Warn (ctx , "unable to set proc niceness" ,
1698
- slog .F ("cmd" , proc .Cmd ()),
1699
- slog .F ("pid" , proc .PID ),
1700
- slog .F ("niceness" , niceness ),
1701
- slog .Error (err ),
1702
- )
1703
- }
1691
+ if ! isBenignProcessErr (err ) {
1692
+ debouncer .Warn (ctx , "unable to set proc niceness" ,
1693
+ slog .F ("cmd" , proc .Cmd ()),
1694
+ slog .F ("pid" , proc .PID ),
1695
+ slog .F ("niceness" , niceness ),
1696
+ slog .Error (err ),
1697
+ )
1704
1698
}
1705
1699
}
1706
1700
1707
1701
// 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.
1708
1702
if oomScore != unsetOOMScore && oomScore != proc .OOMScoreAdj && ! isCustomOOMScore (agentScore , proc ) {
1709
1703
oomScoreStr := strconv .Itoa (oomScore )
1710
1704
err := afero .WriteFile (a .filesystem , fmt .Sprintf ("/proc/%d/oom_score_adj" , proc .PID ), []byte (oomScoreStr ), 0o644 )
1711
- if err != nil && ! xerrors .Is (err , os .ErrPermission ) {
1712
- if ! isNoSuchProcessErr (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
- )
1719
- }
1705
+ if ! isBenignProcessErr (err ) {
1706
+ debouncer .Warn (ctx , "unable to set oom_score_adj" ,
1707
+ slog .F ("cmd" , proc .Cmd ()),
1708
+ slog .F ("pid" , proc .PID ),
1709
+ slog .F ("score" , oomScoreStr ),
1710
+ slog .Error (err ),
1711
+ )
1720
1712
}
1721
1713
}
1722
1714
modProcs = append (modProcs , proc )
@@ -2147,6 +2139,13 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
2147
2139
l .messages [msg ] = time .Now ()
2148
2140
}
2149
2141
2142
+ func isBenignProcessErr (err error ) bool {
2143
+ return err != nil &&
2144
+ (xerrors .Is (err , os .ErrNotExist ) ||
2145
+ xerrors .Is (err , os .ErrPermission ) ||
2146
+ isNoSuchProcessErr (err ))
2147
+ }
2148
+
2150
2149
func isNoSuchProcessErr (err error ) bool {
2151
2150
return err != nil && strings .Contains (err .Error (), "no such process" )
2152
2151
}
0 commit comments