Documentation
¶
Overview ¶
Package osutil contains utilities for functions requiring system calls and other OS-specific APIs. OS-specific network handling should go to github.com/AdguardTeam/golibs/netutil instead.
Index ¶
- func IsReconfigureSignal(sig os.Signal) (ok bool)
- func IsShutdownSignal(sig os.Signal) (ok bool)
- func NotifyReconfigureSignal(n SignalNotifier, c chan<- os.Signal)
- func NotifyShutdownSignal(n SignalNotifier, c chan<- os.Signal)
- func RootDirFS() (fsys fs.FS)
- type DefaultSignalNotifier
- type ExitCode
- type SignalNotifier
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsReconfigureSignal ¶ added in v0.30.3
IsReconfigureSignal returns true if sig is a reconfigure signal.
NOTE: It always returns false on Windows.
func IsShutdownSignal ¶ added in v0.23.2
IsShutdownSignal returns true if sig is a shutdown signal.
func NotifyReconfigureSignal ¶ added in v0.30.3
func NotifyReconfigureSignal(n SignalNotifier, c chan<- os.Signal)
NotifyReconfigureSignal notifies c on receiving reconfigure signals using n.
NOTE: It does nothing on Windows.
func NotifyShutdownSignal ¶ added in v0.23.2
func NotifyShutdownSignal(n SignalNotifier, c chan<- os.Signal)
NotifyShutdownSignal notifies c on receiving shutdown signals using n.
func RootDirFS ¶
RootDirFS returns a filesystem rooted at the system's root directory.
Example ¶
package main
import (
"fmt"
"github.com/AdguardTeam/golibs/osutil"
)
func main() {
fsys := osutil.RootDirFS()
d, err := fsys.Open(".")
if err != nil {
fmt.Printf("opening: %v\n", err)
return
}
fi, err := d.Stat()
if err != nil {
fmt.Printf("getting info: %v\n", err)
return
}
fmt.Printf("is dir: %t\n", fi.IsDir())
err = d.Close()
if err != nil {
fmt.Printf("closing: %v\n", err)
return
}
}
Output: is dir: true
Types ¶
type DefaultSignalNotifier ¶ added in v0.20.0
type DefaultSignalNotifier struct{}
DefaultSignalNotifier is a SignalNotifier that uses signal.Notify and signal.Stop.
func (DefaultSignalNotifier) Notify ¶ added in v0.20.0
func (n DefaultSignalNotifier) Notify(c chan<- os.Signal, sig ...os.Signal)
Notify implements the SignalNotifier interface for DefaultSignalNotifier.
func (DefaultSignalNotifier) Stop ¶ added in v0.20.0
func (n DefaultSignalNotifier) Stop(c chan<- os.Signal)
Stop implements the SignalNotifier interface for DefaultSignalNotifier.
type ExitCode ¶ added in v0.20.0
type ExitCode = int
ExitCode is a semantic alias for int when it's used as an exit code.
type SignalNotifier ¶ added in v0.20.0
type SignalNotifier interface {
// Notify starts relaying incoming signals to c. If no signals are
// provided, all incoming signals are relayed to c. Otherwise, just the
// provided signals are.
//
// Implementations will not block sending to c: the caller must ensure that
// c has sufficient buffer space to keep up with the expected signal rate.
// For a channel used for notification of just one signal value, a buffer of
// size 1 is sufficient.
//
// It is allowed to call Notify multiple times with the same channel: each
// call expands the set of signals sent to that channel. The only way to
// remove signals from the set is to call Stop.
//
// It is allowed to call Notify multiple times with different channels and
// the same signals: each channel receives copies of incoming signals
// independently.
//
// See also [signal.Notify].
Notify(c chan<- os.Signal, sig ...os.Signal)
// Stop causes the SignalNotifier to stop relaying incoming signals to c.
// It undoes the effect of all prior calls to Notify using c. When Stop
// returns, it c must not receive any more signals.
//
// See also [signal.Stop].
Stop(c chan<- os.Signal)
}
SignalNotifier is the interface for OS functions that can notify about incoming signals using a channel.