Documentation
¶
Overview ¶
Package kernel is utilities for the Linux kernel
Index ¶
- Variables
- func AllPidsProcs(procRoot string) ([]int, error)
- func Arch() string
- func GetProcessEnvVariable(pid int, procRoot string, envVar string) (string, error)
- func GetProcessMemFdFile(pid int, procRoot string, memFdFileName string, memFdMaxSize int) ([]byte, error)
- func HostBoot(combineWith ...string) string
- func HostProc(combineWith ...string) string
- func HostSys(combineWith ...string) string
- func IsIPv6Enabled() bool
- func MountInfoPidPath(pid int32) string
- func ParseMountInfoFile(pid int32) ([]*mountinfo.Info, error)
- func ProcessExists(pid int) bool
- func ReadMemFdFile(path string, memFdMaxSize int) ([]byte, error)
- func WithAllProcs(procRoot string, fn func(int) error) error
- type Integer
- type LockdownMode
- type UbuntuKernelVersion
- type Version
Constants ¶
This section is empty.
Variables ¶
var BootRoot = funcs.MemoizeNoError(func() string { if v := os.Getenv("HOST_BOOT"); v != "" { return v } if env.IsContainerized() { if _, err := os.Stat("/host"); err == nil { return "/host/boot" } } return "/boot" })
BootRoot retrieves the current boot dir we should use
var ErrMemFdFileNotFound = errors.New("memfd file not found")
ErrMemFdFileNotFound is an error for when there was no file found for a given process.
var Family = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.family, err
})
Family is the string describing the Linux distribution family (rhel, debian, etc.)
var Machine = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Machine[:]), nil })
Machine is the equivalent of uname -m
var OnlineCPUs = funcs.Memoize(func() ([]uint, error) {
return parseCPUMultipleRangeFromFile("/sys/devices/system/cpu/online")
})
OnlineCPUs returns the individual CPU numbers that are online for the system
var Platform = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.platform, err
})
Platform is the string describing the Linux distribution (ubuntu, debian, fedora, etc.)
var PlatformVersion = funcs.Memoize(func() (string, error) {
pi, err := platformInformation()
return pi.version, err
})
PlatformVersion is the string describing the platform version (`22.04` for Ubuntu jammy, etc.)
var PossibleCPUs = funcs.Memoize(func() (int, error) {
return parseCPUSingleRangeFromFile("/sys/devices/system/cpu/possible")
})
PossibleCPUs returns the max number of CPUs a system may possibly have Logical CPU numbers must be of the form 0-n
var ProcFSRoot = funcs.MemoizeNoError(procFsRoot)
ProcFSRoot retrieves the current procfs dir we should use
var Release = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Release[:]), nil })
Release is the equivalent of uname -r
var RootNSPID = funcs.Memoize(func() (int, error) { pidPath := filepath.Join(ProcFSRoot(), "self") pidStr, err := os.Readlink(pidPath) if err != nil { return 0, err } return strconv.Atoi(pidStr) })
RootNSPID returns the current PID from the root namespace
var SysFSRoot = funcs.MemoizeNoError(func() string { if v := os.Getenv("HOST_SYS"); v != "" { return v } if os.Getenv("DOCKER_DD_AGENT") != "" { if _, err := os.Stat("/host"); err == nil { return "/host/sys" } } return "/sys" })
SysFSRoot retrieves the current sysfs dir we should use
var UnameVersion = funcs.Memoize(func() (string, error) { u, err := uname() if err != nil { return "", err } return unix.ByteSliceToString(u.Version[:]), nil })
UnameVersion is the equivalent of uname -v
Functions ¶
func AllPidsProcs ¶
AllPidsProcs will return all pids under procRoot
func Arch ¶
func Arch() string
Arch returns the kernel architecture value, often used within the kernel `include/arch` directory.
func GetProcessEnvVariable ¶
GetProcessEnvVariable retrieves the given environment variable for the specified process ID, without loading the entire environment into memory. Will return an empty string if the variable is not found.
func GetProcessMemFdFile ¶
func GetProcessMemFdFile(pid int, procRoot string, memFdFileName string, memFdMaxSize int) ([]byte, error)
GetProcessMemFdFile reads a maximum amount of bytes from the memFdFileName if it was found.
func HostBoot ¶
HostBoot returns the location of a host's /boot folder. This can and will be overridden when running inside a container.
func HostProc ¶
HostProc returns the location of a host's procfs. This can and will be overridden when running inside a container.
func HostSys ¶
HostSys returns the location of a host's sysfs. This can and will be overridden when running inside a container.
func IsIPv6Enabled ¶
func IsIPv6Enabled() bool
IsIPv6Enabled returns whether IPv6 has been enabled on the host
func MountInfoPidPath ¶
MountInfoPidPath returns the path to the mountinfo file of a pid in /proc
func ParseMountInfoFile ¶
ParseMountInfoFile collects the mounts for a specific process ID.
func ProcessExists ¶
ProcessExists returns true if the process exists in the procfs
func ReadMemFdFile ¶
ReadMemFdFile reads a maximum amount of bytes from the memfd file at the given path. The path should be a full path to an fd (e.g., /proc/1234/fd/5).
Types ¶
type Integer ¶
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Integer represents all possible integer types. Remove when x/exp/constraints is moved to the standard library.
type LockdownMode ¶
type LockdownMode string
LockdownMode defines a lockdown type
const ( // None mode None LockdownMode = "none" // Integrity mode Integrity LockdownMode = "integrity" // Confidentiality mode Confidentiality LockdownMode = "confidentiality" // Unknown mode Unknown LockdownMode = "unknown" )
type UbuntuKernelVersion ¶
UbuntuKernelVersion represents a version from an ubuntu kernel Please see: https://ubuntu.com/kernel for the documentation of this scheme
func NewUbuntuKernelVersion ¶
func NewUbuntuKernelVersion(unameRelease string) (*UbuntuKernelVersion, error)
NewUbuntuKernelVersion parses the ubuntu release string and returns a structure with each extracted fields
type Version ¶
type Version uint32
Version is a numerical representation of a kernel version
func HostVersion ¶
HostVersion returns the running kernel version of the host
func MustHostVersion ¶
func MustHostVersion() Version
MustHostVersion returns the running kernel version of the host
func ParseReleaseString ¶
ParseReleaseString converts a release string with format 4.4.2[-1] to a kernel version number in LINUX_VERSION_CODE format. That is, for kernel "a.b.c", the version number will be (a<<16 + b<<8 + c)
func ParseVersion ¶
ParseVersion parses a string in the format of x.x.x to a Version
func VersionCode ¶
VersionCode returns a Version computed from the individual parts of a x.x.x version