summaryrefslogtreecommitdiff
path: root/vendor/github.com/cilium/ebpf/internal/feature.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2025-02-03 10:12:35 +0000
committerLibravatar GitHub <noreply@github.com>2025-02-03 10:12:35 +0000
commitc086d4048c2a26a0bf70c1ced24c78680a786710 (patch)
treecf7606e8452e9047d7f0e0d9b6de10edf7ebdc89 /vendor/github.com/cilium/ebpf/internal/feature.go
parent[chore]: Bump golang.org/x/oauth2 from 0.24.0 to 0.25.0 (#3725) (diff)
downloadgotosocial-c086d4048c2a26a0bf70c1ced24c78680a786710.tar.xz
[chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.1 to 0.7.0 (#3726)
Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.1 to 0.7.0. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.1...v0.7.0) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/cilium/ebpf/internal/feature.go')
-rw-r--r--vendor/github.com/cilium/ebpf/internal/feature.go100
1 files changed, 0 insertions, 100 deletions
diff --git a/vendor/github.com/cilium/ebpf/internal/feature.go b/vendor/github.com/cilium/ebpf/internal/feature.go
deleted file mode 100644
index 0a6c2d1d5..000000000
--- a/vendor/github.com/cilium/ebpf/internal/feature.go
+++ /dev/null
@@ -1,100 +0,0 @@
-package internal
-
-import (
- "errors"
- "fmt"
- "sync"
-)
-
-// ErrNotSupported indicates that a feature is not supported by the current kernel.
-var ErrNotSupported = errors.New("not supported")
-
-// UnsupportedFeatureError is returned by FeatureTest() functions.
-type UnsupportedFeatureError struct {
- // The minimum Linux mainline version required for this feature.
- // Used for the error string, and for sanity checking during testing.
- MinimumVersion Version
-
- // The name of the feature that isn't supported.
- Name string
-}
-
-func (ufe *UnsupportedFeatureError) Error() string {
- if ufe.MinimumVersion.Unspecified() {
- return fmt.Sprintf("%s not supported", ufe.Name)
- }
- return fmt.Sprintf("%s not supported (requires >= %s)", ufe.Name, ufe.MinimumVersion)
-}
-
-// Is indicates that UnsupportedFeatureError is ErrNotSupported.
-func (ufe *UnsupportedFeatureError) Is(target error) bool {
- return target == ErrNotSupported
-}
-
-type featureTest struct {
- sync.RWMutex
- successful bool
- result error
-}
-
-// FeatureTestFn is used to determine whether the kernel supports
-// a certain feature.
-//
-// The return values have the following semantics:
-//
-// err == ErrNotSupported: the feature is not available
-// err == nil: the feature is available
-// err != nil: the test couldn't be executed
-type FeatureTestFn func() error
-
-// FeatureTest wraps a function so that it is run at most once.
-//
-// name should identify the tested feature, while version must be in the
-// form Major.Minor[.Patch].
-//
-// Returns an error wrapping ErrNotSupported if the feature is not supported.
-func FeatureTest(name, version string, fn FeatureTestFn) func() error {
- ft := new(featureTest)
- return func() error {
- ft.RLock()
- if ft.successful {
- defer ft.RUnlock()
- return ft.result
- }
- ft.RUnlock()
- ft.Lock()
- defer ft.Unlock()
- // check one more time on the off
- // chance that two go routines
- // were able to call into the write
- // lock
- if ft.successful {
- return ft.result
- }
- err := fn()
- switch {
- case errors.Is(err, ErrNotSupported):
- v, err := NewVersion(version)
- if err != nil {
- return err
- }
-
- ft.result = &UnsupportedFeatureError{
- MinimumVersion: v,
- Name: name,
- }
- fallthrough
-
- case err == nil:
- ft.successful = true
-
- default:
- // We couldn't execute the feature test to a point
- // where it could make a determination.
- // Don't cache the result, just return it.
- return fmt.Errorf("detect support for %s: %w", name, err)
- }
-
- return ft.result
- }
-}