limits

package
v0.0.0-...-ba09d25 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package limits provides resource limits.

Index

Constants

View Source
const (
	// CtxLimits is a Context.Value key for a LimitSet.
	CtxLimits contextID = iota
)
View Source
const Infinity = ^uint64(0)

Infinity is a constant representing a resource with no limit.

Variables

FromLinuxResource maps linux resources to sentry LimitTypes.

Functions

func FromLinux

func FromLinux(rl uint64) uint64

FromLinux maps linux rlimit values to sentry Limits, being careful to handle infinities.

func ToLinux

func ToLinux(l uint64) uint64

ToLinux maps sentry Limits to linux rlimit values, being careful to handle infinities.

Types

type Limit

type Limit struct {
	// Cur specifies the current limit.
	Cur uint64
	// Max specifies the maximum settable limit.
	Max uint64
}

Limit specifies a system limit.

+stateify savable

type LimitSet

type LimitSet struct {
	// contains filtered or unexported fields
}

LimitSet represents the Limits that correspond to each LimitType.

+stateify savable

func FromContext

func FromContext(ctx context.Context) *LimitSet

FromContext returns the limits that apply to ctx.

func FromContextOrDie

func FromContextOrDie(ctx context.Context) *LimitSet

FromContextOrDie returns FromContext(ctx) if the latter is not nil. Otherwise, panic is triggered.

func NewLimitSet

func NewLimitSet() *LimitSet

NewLimitSet creates a new, empty LimitSet.

func NewLinuxDistroLimitSet

func NewLinuxDistroLimitSet() (*LimitSet, error)

NewLinuxDistroLimitSet returns a new LimitSet whose values are typical for a booted Linux distro.

Many Linux init systems adjust the default Linux limits to values more expected by the rest of the userspace. NewLinuxDistroLimitSet returns a LimitSet with sensible defaults for applications that aren't starting their own init system.

func NewLinuxLimitSet

func NewLinuxLimitSet() (*LimitSet, error)

NewLinuxLimitSet returns a LimitSet whose values match the default rlimits in Linux.

func (*LimitSet) Get

func (l *LimitSet) Get(t LimitType) Limit

Get returns the resource limit associated with LimitType t. If no limit is provided, it defaults to an infinite limit.Infinity.

func (*LimitSet) GetCapped

func (l *LimitSet) GetCapped(t LimitType, max uint64) uint64

GetCapped returns the current value for the limit, capped as specified.

func (*LimitSet) GetCopy

func (l *LimitSet) GetCopy() *LimitSet

GetCopy returns a clone of the LimitSet.

func (*LimitSet) Set

func (l *LimitSet) Set(t LimitType, v Limit, privileged bool) (Limit, error)

Set assigns value v to resource of LimitType t and returns the old value. privileged should be true only when either the caller has CAP_SYS_RESOURCE or when creating limits for a new kernel.

func (*LimitSet) SetUnchecked

func (l *LimitSet) SetUnchecked(t LimitType, v Limit)

SetUnchecked assigns value v to resource of LimitType t.

type LimitType

type LimitType int

LimitType defines a type of resource limit.

const (
	CPU LimitType = iota
	FileSize
	Data
	Stack
	Core
	Rss
	ProcessCount
	NumberOfFiles
	MemoryLocked
	AS
	Locks
	SignalsPending
	MessageQueueBytes
	Nice
	RealTimePriority
	Rttime
)

Set of constants defining the different types of resource limits.

Jump to

Keyboard shortcuts

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