aghos

package
v0.0.0-...-75a31e8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: GPL-3.0 Imports: 22 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 (
	DefaultPermDir  fs.FileMode = 0o700
	DefaultPermExe  fs.FileMode = 0o700
	DefaultPermFile fs.FileMode = 0o600
)

Default file, binary, and directory permissions.

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 Chmod

func Chmod(name string, perm fs.FileMode) (err error)

Chmod is an extension for os.Chmod that properly handles Windows access rights.

func ConfigureSyslog

func ConfigureSyslog(serviceName string) (err 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 Mkdir

func Mkdir(name string, perm fs.FileMode) (err error)

Mkdir is an extension for os.Mkdir that properly handles Windows access rights.

func MkdirAll

func MkdirAll(path string, perm fs.FileMode) (err error)

MkdirAll is an extension for os.MkdirAll that properly handles Windows access rights.

func OpenFile

func OpenFile(name string, flag int, perm fs.FileMode) (file *os.File, err error)

OpenFile is an extension for os.OpenFile that properly handles Windows access rights.

func PIDByCommand

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

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

func SendShutdownSignal(c chan<- os.Signal)

SendShutdownSignal sends the shutdown signal to the channel.

func SetGroup

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/andrzejlapinski/AdGuardHome/internal/issues/659.

func SetUser

func SetUser(userName string) (err error)

SetUser sets the effective user ID of the calling process.

func Stat

func Stat(name string) (fi fs.FileInfo, err error)

Stat is an extension for os.Stat that properly handles Windows access rights.

Note that on Windows the "other" permission bits combines the access rights of any trustee that is neither the owner nor the owning group for the file.

TODO(e.burkov): Inspect the behavior for the World (everyone) well-known SID and, perhaps, use it.

func Unsupported

func Unsupported(op string) (err error)

Unsupported is a helper that returns a wrapped errors.ErrUnsupported.

func WriteFile

func WriteFile(filename string, data []byte, perm fs.FileMode) (err error)

WriteFile is an extension for os.WriteFile that properly handles Windows access rights.

Types

type EmptyFSWatcher

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

func (EmptyFSWatcher) Add(_ string) (err error)

Add implements the FSWatcher interface for EmptyFSWatcher. It always returns nil error.

func (EmptyFSWatcher) Close

func (EmptyFSWatcher) Close() (err error)

Close implements the FSWatcher interface for EmptyFSWatcher. It always returns nil error.

func (EmptyFSWatcher) Events

func (EmptyFSWatcher) Events() (e <-chan event)

Events implements the FSWatcher interface for EmptyFSWatcher. It always returns nil channel.

func (EmptyFSWatcher) Start

func (EmptyFSWatcher) Start() (err error)

Start implements the FSWatcher interface for EmptyFSWatcher. It always returns nil error.

type FSWatcher

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

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

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

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.

Jump to

Keyboard shortcuts

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