snapdtool

package
v0.0.0-...-a278e5a Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: GPL-3.0 Imports: 20 Imported by: 186

Documentation

Overview

Package snapdtool exposes version and related information, supports re-execution and inter-tool lookup/execution across all snapd tools.

Index

Constants

This section is empty.

Variables

View Source
var Version = "unknown"

Version will be overwritten at build-time via mkversion.sh

Functions

func CommandFromSystemSnap

func CommandFromSystemSnap(name string, cmdArgs ...string) (*exec.Cmd, error)

CommandFromSystemSnap runs a command from the snapd/core snap using the proper interpreter and library paths if needed.

Files from core need this hack. Files from snapd are executed normally unless the snapd snap is not mounted under /snap.

At the moment it can only run ELF files, expects a standard ld.so interpreter, and can't handle RPATH.

func CommandFromSystemSnapWithCmdBuilder

func CommandFromSystemSnapWithCmdBuilder(createCmd func(name string, arg ...string) *exec.Cmd, name string, cmdArgs ...string) (*exec.Cmd, error)

func CommandFromSystemSnapWithContext

func CommandFromSystemSnapWithContext(ctx context.Context, name string, cmdArgs ...string) (*exec.Cmd, error)

CommandFromSystemSnapWithContext does the same as CommandFromSystemSnap, but accepts a context for command cancellation.

func DispatchWithFIPS

func DispatchWithFIPS(targetExe string) error

DispatchWithFIPS checks whether system-wide FIPS mode is enabled, sets up the environment for FIPS compliance, and execs into targetExe.

func DistroSupportsReExec

func DistroSupportsReExec() bool

DistroSupportsReExec returns true if the distribution we are running on can use re-exec.

This is true by default except for a "core/all" snap system where it makes no sense and in certain distributions that we don't want to enable re-exec yet because of missing validation or other issues.

func ExecInSnapdOrCoreSnap

func ExecInSnapdOrCoreSnap()

ExecInSnapdOrCoreSnap makes sure you're executing the binary that ships in the snapd/core snap.

func InternalToolPath

func InternalToolPath(tool string) (string, error)

InternalToolPath returns the path of an internal snapd tool. The tool *must* be located inside the same tree as the current binary.

The return value is either the path of the tool in the current distribution or in the core/snapd snap (or the ubuntu-core snap) if the current binary is ran from that location.

func IsReexecEnabled

func IsReexecEnabled() bool

IsReexecEnabled checks the environment and configuration to assert whether reexec has been explicitly enabled/disabled.

func IsReexecExplicitlyEnabled

func IsReexecExplicitlyEnabled() bool

IsReexecExplicitlyEnabled is a stronger check than IsReexecEnabled as it really expects the relevant environment variable to be set.

func IsReexecForced

func IsReexecForced() bool

IsReexecForced returns true if reexec is explicitly forced.

func IsReexecd

func IsReexecd() (bool, error)

IsReexecd returns true when the current process binary is running from a snap.

func MaybeCompleteFIPSSetup

func MaybeCompleteFIPSSetup()

MaybeCompleteFIPSSetup run completion and cleanup steps if the process was invoked through FIPS execution dispatch mechanism.

func MockCoreSnapdPaths

func MockCoreSnapdPaths(newCoreSnap, newSnapdSnap string) func()

MockCoreSnapdPaths is for use in tests

func MockOsReadlink(f func(string) (string, error)) func()

MockOsReadlink is for use in tests

func MockSelfExe

func MockSelfExe(newSelfExe string) func()

MockSelfExe is for use in tests

func MockSyscallExec

func MockSyscallExec(f func(argv0 string, argv []string, envv []string) (err error)) func()

MockSyscallExec is for use in tests

func MockVersion

func MockVersion(version string) (restore func())

func ParseInfoFile

func ParseInfoFile(f io.Reader, whence string) (version string, flags map[string]string, err error)

ParseInfoFile parses the "info" file provided via an io.Reader. It returns the snapd version read from the info file, as well as any other key/value pairs/flags in the file. whence is used to construct error messages as "... info file %s". The format of the "info" file are lines with "KEY=VALUE" with the typical key being just VERSION. The file is produced by mkversion.sh and normally installed along snapd binary in /usr/lib/snapd. Other typical keys in this file include SNAPD_APPARMOR_REEXEC, which indicates whether or not the snapd-apparmor binary installed via the traditional linux package of snapd supports re-exec into the version in the snapd or core snaps.

func SnapdVersionFromInfoFile

func SnapdVersionFromInfoFile(dir string) (version string, flags map[string]string, err error)

SnapdVersionFromInfoFile returns the snapd version read from the info file in the given dir, as well as any other key/value pairs/flags in the file. See ParseInfoFile for more format details.

Types

This section is empty.

Jump to

Keyboard shortcuts

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