aghos

package
v0.107.48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package aghos contains utilities for functions requiring system calls and other OS-specific APIs. OS-specific network handling should go to aghnet instead.

Index

Constants

View Source
const MaxCmdOutputSize = 64 * 1024

MaxCmdOutputSize is the maximum length of performed shell command output in bytes.

Variables

This section is empty.

Functions

func ConfigureSyslog

func ConfigureSyslog(serviceName string) error

ConfigureSyslog reroutes standard logger output to syslog.

func HaveAdminRights

func HaveAdminRights() (bool, error)

HaveAdminRights checks if the current user has root (administrator) rights.

func IsOpenWrt

func IsOpenWrt() (ok bool)

IsOpenWrt returns true if host OS is OpenWrt.

func IsReconfigureSignal added in v0.107.17

func IsReconfigureSignal(sig os.Signal) (ok bool)

IsReconfigureSignal returns true if sig is a reconfigure signal.

func IsShutdownSignal added in v0.107.7

func IsShutdownSignal(sig os.Signal) (ok bool)

IsShutdownSignal returns true if sig is a shutdown signal.

func NotifyReconfigureSignal added in v0.107.17

func NotifyReconfigureSignal(c chan<- os.Signal)

NotifyReconfigureSignal notifies c on receiving reconfigure signals.

func NotifyShutdownSignal added in v0.107.7

func NotifyShutdownSignal(c chan<- os.Signal)

NotifyShutdownSignal notifies c on receiving shutdown signals.

func PIDByCommand added in v0.107.0

func PIDByCommand(command string, except ...int) (pid int, err error)

PIDByCommand searches for process named command and returns its PID ignoring the PIDs from except. If no processes found, the error returned.

func PreCheckActionStart added in v0.107.30

func PreCheckActionStart() (err error)

PreCheckActionStart performs the service start action pre-check.

func RunCommand

func RunCommand(command string, arguments ...string) (code int, output []byte, err error)

RunCommand runs shell command.

func SendShutdownSignal added in v0.107.37

func SendShutdownSignal(c chan<- os.Signal)

SendShutdownSignal sends the shutdown signal to the channel.

func SetGroup added in v0.107.0

func SetGroup(groupName string) (err error)

SetGroup sets the effective group ID of the calling process.

func SetRlimit

func SetRlimit(val uint64) (err error)

SetRlimit sets user-specified limit of how many fd's we can use.

See https://github.com/AdguardTeam/AdGuardHome/internal/issues/659.

func SetUser added in v0.107.0

func SetUser(userName string) (err error)

SetUser sets the effective user ID of the calling process.

func Unsupported added in v0.107.0

func Unsupported(op string) (err error)

Unsupported is a helper that returns an *UnsupportedError with the Op field set to op and the OS field set to the current OS.

Types

type FSWatcher added in v0.107.0

type FSWatcher interface {
	// Start starts watching the added files.
	Start() (err error)

	// Close stops watching the files and closes an update channel.
	io.Closer

	// Events returns the channel to notify about the file system events.
	Events() (e <-chan event)

	// Add starts tracking the file.  It returns an error if the file can't be
	// tracked.  It must not be called after Start.
	Add(name string) (err error)
}

FSWatcher tracks all the fyle system events and notifies about those.

TODO(e.burkov, a.garipov): Move into another package like aghfs.

TODO(e.burkov): Add tests.

func NewOSWritesWatcher added in v0.107.0

func NewOSWritesWatcher() (w FSWatcher, err error)

NewOSWritesWatcher creates FSWatcher that tracks the real file system of the OS and notifies only about writing events.

type FileWalker added in v0.107.0

type FileWalker func(r io.Reader) (patterns []string, cont bool, err error)

FileWalker is the signature of a function called for files in the file tree. As opposed to filepath.Walk it only walk the files (not directories) matching the provided pattern and those returned by function itself. All patterns should be valid for fs.Glob. If FileWalker returns false for cont then walking terminates. Prefer using bufio.Scanner to read the r since the input is not limited.

TODO(e.burkov, a.garipov): Move into another package like aghfs.

TODO(e.burkov): Think about passing filename or any additional data.

func (FileWalker) Walk added in v0.107.0

func (fw FileWalker) Walk(fsys fs.FS, initial ...string) (ok bool, err error)

Walk starts walking the files in fsys defined by patterns from initial. It only returns true if fw signed to stop walking.

type UnsupportedError added in v0.107.0

type UnsupportedError struct {
	Op string
	OS string
}

UnsupportedError is returned by functions and methods when a particular operation Op cannot be performed on the current OS.

func (*UnsupportedError) Error added in v0.107.0

func (err *UnsupportedError) Error() (msg string)

Error implements the error interface for *UnsupportedError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL