mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-29 10:08:17 +03:00
2a546aa609
Updates #6711.
Squashed commit of the following:
commit 3ddfe809f76325c2d4cda0715a7bcc15e76a2388
Merge: 185957cd0 d338451fa
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Feb 13 13:01:30 2024 +0300
Merge branch 'master' into 6711-watch-hosts
commit 185957cd01516e5955e388108615e6f131d6ad71
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Fri Feb 9 18:11:41 2024 +0300
aghos: imp docs
commit 3afbbcbb7ab6cc60c7c40ef8acd5b3ddf52cb3d1
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Fri Feb 9 15:40:02 2024 +0300
all: upd golibs, imp fswatcher
47 lines
1,014 B
Go
47 lines
1,014 B
Go
//go:build linux
|
|
|
|
package aghos
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"syscall"
|
|
|
|
"github.com/AdguardTeam/golibs/osutil"
|
|
"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) {
|
|
const etcReleasePattern = "etc/*release*"
|
|
|
|
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(osutil.RootDirFS(), etcReleasePattern)
|
|
|
|
return err == nil && ok
|
|
}
|