AdGuardHome/internal/aghos/os.go
Ainar Garipov 6a8f6357e2 Pull request: all: mv IsOpenWrt
Updates #2829.

Squashed commit of the following:

commit a284a26ba5df101c78e6f866d1bdfa540d205666
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Apr 8 20:34:20 2021 +0300

    aghos: fix darwin

commit 9dbd42d75ebb048c83dbd06a1f09d950b3d12181
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Apr 8 20:11:56 2021 +0300

    all: mv IsOpenWrt
2021-04-08 20:42:04 +03:00

53 lines
1.4 KiB
Go

// Package aghos contains utilities for functions requiring system calls.
package aghos
import (
"fmt"
"os/exec"
"syscall"
)
// CanBindPrivilegedPorts checks if current process can bind to privileged
// ports.
func CanBindPrivilegedPorts() (can bool, err error) {
return canBindPrivilegedPorts()
}
// SetRlimit sets user-specified limit of how many fd's we can use
// https://github.com/AdguardTeam/AdGuardHome/internal/issues/659.
func SetRlimit(val uint) {
setRlimit(val)
}
// HaveAdminRights checks if the current user has root (administrator) rights.
func HaveAdminRights() (bool, error) {
return haveAdminRights()
}
// SendProcessSignal sends signal to a process.
func SendProcessSignal(pid int, sig syscall.Signal) error {
return sendProcessSignal(pid, sig)
}
// MaxCmdOutputSize is the maximum length of performed shell command output.
const MaxCmdOutputSize = 2 * 1024
// RunCommand runs shell command.
func RunCommand(command string, arguments ...string) (int, string, error) {
cmd := exec.Command(command, arguments...)
out, err := cmd.Output()
if len(out) > MaxCmdOutputSize {
out = out[:MaxCmdOutputSize]
}
if err != nil {
return 1, "", fmt.Errorf("exec.Command(%s) failed: %v: %s", command, err, string(out))
}
return cmd.ProcessState.ExitCode(), string(out), nil
}
// IsOpenWrt returns true if host OS is OpenWrt.
func IsOpenWrt() (ok bool) {
return isOpenWrt()
}