@@ -1676,16 +1676,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1676
1676
}
1677
1677
1678
1678
score , 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
+ )
1689
1685
}
1690
1686
1691
1687
// 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
1699
1695
1700
1696
if niceErr == nil {
1701
1697
err := 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
+ )
1711
1705
}
1712
1706
}
1713
1707
1714
1708
// 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.
1715
1709
if oomScore != unsetOOMScore && oomScore != proc .OOMScoreAdj && ! isCustomOOMScore (agentScore , proc ) {
1716
1710
oomScoreStr := strconv .Itoa (oomScore )
1717
1711
err := 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
+ )
1727
1719
}
1728
1720
}
1729
1721
modProcs = append (modProcs , proc )
@@ -2154,6 +2146,13 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
2154
2146
l .messages [msg ] = time .Now ()
2155
2147
}
2156
2148
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
+
2157
2156
func isNoSuchProcessErr (err error ) bool {
2158
2157
return err != nil && strings .Contains (err .Error (), "no such process" )
2159
2158
}
0 commit comments