2019-07-04 11:26:34 +00:00
|
|
|
// +build aix darwin dragonfly linux netbsd openbsd solaris
|
2019-04-16 15:36:10 +00:00
|
|
|
|
2020-02-13 15:42:07 +00:00
|
|
|
package util
|
2019-04-16 15:36:10 +00:00
|
|
|
|
|
|
|
import (
|
2019-04-01 09:22:54 +00:00
|
|
|
"os"
|
2019-04-16 15:36:10 +00:00
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/golibs/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Set user-specified limit of how many fd's we can use
|
|
|
|
// https://github.com/AdguardTeam/AdGuardHome/issues/659
|
2020-02-13 15:42:07 +00:00
|
|
|
func SetRlimit(val uint) {
|
2019-04-16 15:36:10 +00:00
|
|
|
var rlim syscall.Rlimit
|
|
|
|
rlim.Max = uint64(val)
|
|
|
|
rlim.Cur = uint64(val)
|
|
|
|
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Setrlimit() failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 09:22:54 +00:00
|
|
|
|
|
|
|
// Check if the current user has root (administrator) rights
|
2020-02-13 15:42:07 +00:00
|
|
|
func HaveAdminRights() (bool, error) {
|
2019-04-01 09:22:54 +00:00
|
|
|
return os.Getuid() == 0, nil
|
|
|
|
}
|
2020-02-18 13:01:32 +00:00
|
|
|
|
|
|
|
// SendProcessSignal - send signal to a process
|
|
|
|
func SendProcessSignal(pid int, sig syscall.Signal) error {
|
|
|
|
return syscall.Kill(pid, sig)
|
|
|
|
}
|