2021-05-21 11:55:42 +00:00
|
|
|
//go:build linux
|
2021-06-15 16:42:41 +00:00
|
|
|
// +build linux
|
2021-05-21 11:55:42 +00:00
|
|
|
|
2021-03-16 16:42:15 +00:00
|
|
|
package aghos
|
2020-11-30 16:23:14 +00:00
|
|
|
|
|
|
|
import (
|
2021-08-13 16:20:17 +00:00
|
|
|
"io"
|
2020-11-30 16:23:14 +00:00
|
|
|
"os"
|
|
|
|
"syscall"
|
2021-08-13 16:20:17 +00:00
|
|
|
|
|
|
|
"github.com/AdguardTeam/golibs/stringutil"
|
2020-11-30 16:23:14 +00:00
|
|
|
)
|
|
|
|
|
2021-06-03 18:04:13 +00:00
|
|
|
func setRlimit(val uint64) (err error) {
|
2020-11-30 16:23:14 +00:00
|
|
|
var rlim syscall.Rlimit
|
2021-06-03 18:04:13 +00:00
|
|
|
rlim.Max = val
|
|
|
|
rlim.Cur = val
|
|
|
|
|
|
|
|
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
|
2020-11-30 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func haveAdminRights() (bool, error) {
|
2020-12-04 14:06:19 +00:00
|
|
|
// The error is nil because the platform-independent function signature
|
|
|
|
// requires returning an error.
|
2020-11-30 16:23:14 +00:00
|
|
|
return os.Getuid() == 0, nil
|
|
|
|
}
|
|
|
|
|
2021-04-08 17:42:04 +00:00
|
|
|
func isOpenWrt() (ok bool) {
|
2021-10-14 16:39:21 +00:00
|
|
|
const etcReleasePattern = "etc/*release*"
|
|
|
|
|
2021-08-13 16:20:17 +00:00
|
|
|
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)
|
2021-04-08 17:42:04 +00:00
|
|
|
if err != nil {
|
2021-08-13 16:20:17 +00:00
|
|
|
return nil, false, err
|
2021-04-08 17:42:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 16:20:17 +00:00
|
|
|
return nil, !stringutil.ContainsFold(string(data), osNameData), nil
|
2021-10-14 16:39:21 +00:00
|
|
|
}).Walk(RootDirFS(), etcReleasePattern)
|
2021-04-08 17:42:04 +00:00
|
|
|
|
2021-08-13 16:20:17 +00:00
|
|
|
return err == nil && ok
|
2021-04-08 17:42:04 +00:00
|
|
|
}
|