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
- func ConfigureSyslog(serviceName string) (err error)
- func HaveAdminRights() (bool, error)
- func IsOpenWrt() (ok bool)
- func PIDByCommand(ctx context.Context, l *slog.Logger, command string, except ...int) (pid int, err error)
- func PreCheckActionStart() (err error)
- func RootDir() (dir string)
- func RunCommand(ctx context.Context, cmdCons executil.CommandConstructor, command string, ...) (code int, output []byte, err error)
- func SendShutdownSignal(c chan<- os.Signal)
- func SetGroup(groupName string) (err error)
- func SetRlimit(val uint64) (err error)
- func SetUser(userName string) (err error)
- func Unsupported(op string) (err error)
- type EmptyFSWatcher
- type Event
- type FSWatcher
- type FileWalker
- type OSWatcher
- type OSWatcherConfig
Constants ¶
const ( DefaultPermDir fs.FileMode = 0o700 DefaultPermExe fs.FileMode = 0o700 DefaultPermFile fs.FileMode = 0o600 )
Default file, binary, and directory permissions.
const MaxCmdOutputSize = 64 * 1024
MaxCmdOutputSize is the maximum length of performed shell command output in bytes.
Variables ¶
This section is empty.
Functions ¶
func ConfigureSyslog ¶
ConfigureSyslog reroutes standard logger output to syslog.
func HaveAdminRights ¶
HaveAdminRights checks if the current user has root (administrator) rights.
func PIDByCommand ¶ added in v0.107.0
func PIDByCommand( ctx context.Context, l *slog.Logger, 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. l must not be nil.
func PreCheckActionStart ¶ added in v0.107.30
func PreCheckActionStart() (err error)
PreCheckActionStart performs the service start action pre-check.
func RootDir ¶ added in v0.107.72
func RootDir() (dir string)
RootDir returns the root directory for the current OS.
TODO(e.burkov): Deprecate osutil.RootDirFS and move it there.
func RunCommand ¶
func RunCommand( ctx context.Context, cmdCons executil.CommandConstructor, command string, arguments ...string, ) (code int, output []byte, err error)
RunCommand runs shell command.
TODO(s.chzhen): Consider removing this after addressing the current behavior where a non-zero exit code is returned together with a nil error.
func SendShutdownSignal ¶ added in v0.107.37
SendShutdownSignal sends the shutdown signal to the channel.
func SetRlimit ¶
SetRlimit sets user-specified limit of how many fd's we can use.
See https://github.com/AdguardTeam/AdGuardHome/internal/issues/659.
func Unsupported ¶ added in v0.107.0
Unsupported is a helper that returns a wrapped errors.ErrUnsupported.
Types ¶
type EmptyFSWatcher ¶ added in v0.107.52
type EmptyFSWatcher struct{}
EmptyFSWatcher is a no-op implementation of the FSWatcher interface. It may be used on systems not supporting filesystem events.
func (EmptyFSWatcher) Add ¶ added in v0.107.52
func (EmptyFSWatcher) Add(_ string) (err error)
Add implements the FSWatcher interface for EmptyFSWatcher. It always returns nil error.
func (EmptyFSWatcher) Events ¶ added in v0.107.52
func (EmptyFSWatcher) Events() (e <-chan Event)
Events implements the FSWatcher interface for EmptyFSWatcher. It always returns nil channel.
func (EmptyFSWatcher) Remove ¶ added in v0.107.72
func (EmptyFSWatcher) Remove(_ string) (err error)
Remove implements the FSWatcher interface for EmptyFSWatcher. It always returns nil error.
type Event ¶ added in v0.107.72
type Event = struct{}
Event is a convenient alias for an empty struct to signal that watched file event happened.
type FSWatcher ¶ added in v0.107.0
type FSWatcher interface {
service.Interface
// 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. Adding the same file multiple times must not result in an
// error.
Add(name string) (err error)
// Remove stops tracking the file. Removing a non-tracked file must not
// result in an error.
Remove(name string) (err error)
}
FSWatcher tracks all the file system events and notifies about those.
TODO(e.burkov, a.garipov): Move into another package like aghfs.
type FileWalker ¶ added in v0.107.0
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.
type OSWatcher ¶ added in v0.107.72
type OSWatcher struct {
// contains filtered or unexported fields
}
OSWatcher tracks the file system provided by the OS.
TODO(e.burkov): Add tests.
func NewOSWatcher ¶ added in v0.107.72
func NewOSWatcher(c *OSWatcherConfig) (w *OSWatcher, err error)
NewOSWatcher creates an FSWatcher that tracks the file system of the OS. c must not be nil.
func (*OSWatcher) Add ¶ added in v0.107.72
Add implements the FSWatcher interface for *OSWatcher. It's safe for concurrent use.
TODO(e.burkov): Make it accept non-existing files to detect it's creating.
func (*OSWatcher) Events ¶ added in v0.107.72
Events implements the FSWatcher interface for *OSWatcher.
func (*OSWatcher) Remove ¶ added in v0.107.72
Remove implements the FSWatcher interface for *OSWatcher. It's safe for concurrent use.
func (*OSWatcher) Shutdown ¶ added in v0.107.72
Shutdown implements the service.Interface interface for *OSWatcher.
type OSWatcherConfig ¶ added in v0.107.72
type OSWatcherConfig struct {
// Logger is used for logging the operations of watcher. It must not be
// nil.
Logger *slog.Logger
}
OSWatcherConfig is the configuration structure for NewOSWatcher.
TODO(e.burkov): Consider using os.Root.