Documentation
¶
Index ¶
- Constants
- Variables
- func BootSessionID() (string, error)
- func DNSAddresses() ([]string, error)
- func Dup2(oldfd, newfd int) (err error)
- func FileExists(path string) bool
- func HandleExitError(err error)
- func IsBeingRosettaTranslated() bool
- func IsEACCES(err error) bool
- func LimaUser(ctx context.Context, limaVersion string, warn bool, guestOS *limatype.OS) *user.User
- func ProcessAlive(pid int) bool
- func ProductVersion() (*semver.Version, error)
- func ProxySettings() (map[string]string, error)
- func RemoveStaleSocket(path string) error
- func SignalName(sig os.Signal) string
- func SysKill(pid int, sig Signal) error
- func Sysctl(ctx context.Context, name string) (string, error)
- func Touch(path string) error
- func WriteFileBeneathDir(name string, data []byte, perm os.FileMode) error
- type Group
- type Signal
- type Stat
- type User
Constants ¶
const SigInt = Signal(syscall.SIGINT)
SigInt is the value of SIGINT.
const SigKill = Signal(syscall.SIGKILL)
SigKill is the value of SIGKILL.
const SigTerm = Signal(syscall.SIGTERM)
SigTerm is the value of SIGTERM.
const UnixPathMax = 108
UnixPathMax is the value of UNIX_PATH_MAX.
Variables ¶
var ErrBootSessionNotSupported = errors.New("boot session ID is not supported on this platform")
ErrBootSessionNotSupported is returned by BootSessionID on platforms that do not expose an identifier of the current boot.
var MachineID = sync.OnceValue(func() string { x, err := machineID(context.Background()) if err == nil && x != "" { return x } logrus.WithError(err).Debug("failed to get machine ID, falling back to use hostname instead") hostname, err := os.Hostname() if err != nil { panic(fmt.Errorf("failed to get hostname: %w", err)) } return hostname })
Functions ¶
func BootSessionID ¶ added in v2.2.1
BootSessionID returns an identifier of the current boot of the host. The identifier changes on every reboot, so it can be used to detect state that was left behind by a previous boot.
func DNSAddresses ¶
func FileExists ¶ added in v2.1.0
FileExists reports whether path exists and is accessible. It returns true for any non-ErrNotExist stat result, including permission errors.
func HandleExitError ¶
func HandleExitError(err error)
HandleExitError calls os.Exit immediately without printing an error, only if the error is an *exec.ExitError (non-nil).
The function does not call os.Exit if the error is of any other type, even if it wraps an *exec.ExitError, so that the caller can print the error message.
func IsBeingRosettaTranslated ¶
func IsBeingRosettaTranslated() bool
func ProcessAlive ¶ added in v2.2.0
ProcessAlive reports whether the process with the given PID is still running.
func ProductVersion ¶
ProductVersion returns the OS product version, not the kernel version.
func ProxySettings ¶
func RemoveStaleSocket ¶
RemoveStaleSocket removes path so a fresh listener can bind to it, but only when path is a Unix domain socket. A hostSocket comes from the instance config (which may originate from an untrusted template) and is validated only as an absolute path, so it can point at an existing directory or regular file. os.RemoveAll on such a path would delete it recursively; here anything that is not a socket is left in place and an error is returned instead. A non-existent path is not an error.
func SignalName ¶
func WriteFileBeneathDir ¶ added in v2.2.0
WriteFileBeneathDir writes data to name without following a symlink at the final path component. It is meant for destinations that untrusted code may be able to write to, e.g. a path inside a writable mount: a symlink planted at name (say pointing at ~/.ssh/authorized_keys) would otherwise get the bytes written through the link to a file outside the intended directory. os.OpenRoot confines the write to name's parent directory, so a symlink whose target escapes that directory is refused.