osutil

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Unlicense Imports: 4 Imported by: 3

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsShutdownSignal added in v0.23.2

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

IsShutdownSignal returns true if sig is a shutdown signal.

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

func RootDirFS() (fsys fs.FS)

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.

const (
	ExitCodeSuccess ExitCode = 0
	ExitCodeFailure ExitCode = 1
)

Exit status constants.

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.

Jump to

Keyboard shortcuts

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