From 98ff11e1c781a373768f01c54f6c7c29d8096d32 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Thu, 4 Jul 2019 14:26:34 +0300 Subject: [PATCH] - freebsd: fix build Go's "syscall" package file for FreeBSD (incorrectly?) uses int64 types in syscall.Rlimit struct. --- home/os_freebsd.go | 27 +++++++++++++++++++++++++++ home/os_unix.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 home/os_freebsd.go diff --git a/home/os_freebsd.go b/home/os_freebsd.go new file mode 100644 index 00000000..43ee223e --- /dev/null +++ b/home/os_freebsd.go @@ -0,0 +1,27 @@ +// +build freebsd + +package home + +import ( + "os" + "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 +func setRlimit(val uint) { + var rlim syscall.Rlimit + rlim.Max = int64(val) + rlim.Cur = int64(val) + err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) + if err != nil { + log.Error("Setrlimit() failed: %v", err) + } +} + +// Check if the current user has root (administrator) rights +func haveAdminRights() (bool, error) { + return os.Getuid() == 0, nil +} diff --git a/home/os_unix.go b/home/os_unix.go index d55aa72f..2623376e 100644 --- a/home/os_unix.go +++ b/home/os_unix.go @@ -1,4 +1,4 @@ -// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris +// +build aix darwin dragonfly linux netbsd openbsd solaris package home