()
| 44 | } |
| 45 | |
| 46 | func NewExecer() (Execer, error) { |
| 47 | _, enabled := os.LookupEnv(EnvProcPrioMgmt) |
| 48 | if runtime.GOOS != "linux" || !enabled { |
| 49 | return DefaultExecer, nil |
| 50 | } |
| 51 | |
| 52 | executable, err := os.Executable() |
| 53 | if err != nil { |
| 54 | return nil, xerrors.Errorf("get executable: %w", err) |
| 55 | } |
| 56 | |
| 57 | bin, err := filepath.EvalSymlinks(executable) |
| 58 | if err != nil { |
| 59 | return nil, xerrors.Errorf("eval symlinks: %w", err) |
| 60 | } |
| 61 | |
| 62 | oomScore, ok := envValInt(EnvProcOOMScore) |
| 63 | if !ok { |
| 64 | oomScore = unset |
| 65 | } |
| 66 | |
| 67 | niceScore, ok := envValInt(EnvProcNiceScore) |
| 68 | if !ok { |
| 69 | niceScore = unset |
| 70 | } |
| 71 | |
| 72 | return priorityExecer{ |
| 73 | binPath: bin, |
| 74 | oomScore: oomScore, |
| 75 | niceScore: niceScore, |
| 76 | }, nil |
| 77 | } |
| 78 | |
| 79 | type execer struct{} |
| 80 |
no test coverage detected