AdGuardHome/internal/aghos/os_linux.go
Eugene Burkov 550b1798a1 Pull request: 3457 fix service reload
Merge in DNS/adguard-home from 3457-darwin-svc-reload to master

Closes #3457.

Squashed commit of the following:

commit e3d6fbccf8373194360b6480e2d702ccd0ec7107
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Wed Aug 18 00:52:39 2021 +0300

    aghos: imp docs

commit 220d37ebc1e0c2e9ba37a34650bff1480bd2fcf6
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Tue Aug 17 15:45:52 2021 +0300

    all: fix ps
2021-08-18 13:20:56 +03:00

46 lines
925 B
Go

//go:build linux
// +build linux
package aghos
import (
"io"
"os"
"syscall"
"github.com/AdguardTeam/golibs/stringutil"
)
func setRlimit(val uint64) (err error) {
var rlim syscall.Rlimit
rlim.Max = val
rlim.Cur = val
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
}
func haveAdminRights() (bool, error) {
// The error is nil because the platform-independent function signature
// requires returning an error.
return os.Getuid() == 0, nil
}
func isOpenWrt() (ok bool) {
var err error
ok, err = FileWalker(func(r io.Reader) (_ []string, cont bool, err error) {
const osNameData = "openwrt"
// This use of ReadAll is now safe, because FileWalker's Walk()
// have limited r.
var data []byte
data, err = io.ReadAll(r)
if err != nil {
return nil, false, err
}
return nil, !stringutil.ContainsFold(string(data), osNameData), nil
}).Walk("/etc/*release*")
return err == nil && ok
}