Skip to content

Commit

Permalink
fix darwin release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Slach committed Oct 12, 2023
1 parent 3561a39 commit 8f6fe6b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
15 changes: 2 additions & 13 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"crypto/tls"
"fmt"
"github.com/xyproto/gionice"
"math"
"os"
"runtime"
Expand Down Expand Up @@ -325,19 +324,9 @@ func LoadConfig(configLocation string) (*Config, error) {
if err = ValidateConfig(cfg); err != nil {
return cfg, err
}
if cfg.General.IONicePriority != "" {
var nicePriority gionice.PriClass
if nicePriority, err = gionice.Parse(cfg.General.IONicePriority); err != nil {
return cfg, err
}
if err = gionice.SetIDPri(0, nicePriority, 7, gionice.IOPRIO_WHO_PGRP); err != nil {
log.Warnf("can't set i/o priority %s, error: %v", cfg.General.IONicePriority, err)
}
}
if err = gionice.SetNicePri(0, gionice.PRIO_PROCESS, cfg.General.CPUNicePriority); err != nil {
log.Warnf("can't set CPU priority %s, error: %v", cfg.General.CPUNicePriority, err)
if err = cfg.SetPriority(); err != nil {
return cfg, err
}

return cfg, nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/config/config_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package config

import (
"github.com/apex/log"
"syscall"
)

func (cfg *Config) SetPriority() error {
if err := syscall.Setpriority(0, 0, cfg.General.CPUNicePriority); err != nil {
log.Warnf("can't set CPU priority %s, error: %v", cfg.General.CPUNicePriority, err)
}
return nil
}
23 changes: 23 additions & 0 deletions pkg/config/config_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config

import (
"github.com/apex/log"
"github.com/xyproto/gionice"
)

func (cfg *Config) SetPriority() error {
var err error
if cfg.General.IONicePriority != "" {
var nicePriority gionice.PriClass
if nicePriority, err = gionice.Parse(cfg.General.IONicePriority); err != nil {
return err
}
if err = gionice.SetIDPri(0, nicePriority, 7, gionice.IOPRIO_WHO_PGRP); err != nil {
log.Warnf("can't set i/o priority %s, error: %v", cfg.General.IONicePriority, err)
}
}
if err = gionice.SetNicePri(0, gionice.PRIO_PROCESS, cfg.General.CPUNicePriority); err != nil {
log.Warnf("can't set CPU priority %s, error: %v", cfg.General.CPUNicePriority, err)
}
return nil
}

0 comments on commit 8f6fe6b

Please sign in to comment.