Skip to content

Commit e943a2b

Browse files
Merge pull request #25275 from dfr/freebsd-hascapresource
libpod: make hasCapSysResource platform-specific
2 parents 8bb1768 + ab04109 commit e943a2b

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

libpod/container_internal_common.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"slices"
1919
"strconv"
2020
"strings"
21-
"sync"
2221
"syscall"
2322
"time"
2423

@@ -53,7 +52,6 @@ import (
5352
"github.com/containers/storage/pkg/unshare"
5453
stypes "github.com/containers/storage/types"
5554
securejoin "github.com/cyphar/filepath-securejoin"
56-
"github.com/moby/sys/capability"
5755
runcuser "github.com/moby/sys/user"
5856
spec "github.com/opencontainers/runtime-spec/specs-go"
5957
"github.com/opencontainers/runtime-tools/generate"
@@ -179,18 +177,6 @@ func getOverlayUpperAndWorkDir(options []string) (string, string, error) {
179177
return upperDir, workDir, nil
180178
}
181179

182-
// hasCapSysResource returns whether the current process has CAP_SYS_RESOURCE.
183-
var hasCapSysResource = sync.OnceValues(func() (bool, error) {
184-
currentCaps, err := capability.NewPid2(0)
185-
if err != nil {
186-
return false, err
187-
}
188-
if err = currentCaps.Load(); err != nil {
189-
return false, err
190-
}
191-
return currentCaps.Get(capability.EFFECTIVE, capability.CAP_SYS_RESOURCE), nil
192-
})
193-
194180
// Generate spec for a container
195181
// Accepts a map of the container's dependencies
196182
func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFuncRet func(), err error) {

libpod/container_internal_freebsd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,8 @@ func (c *Container) hasPrivateUTS() bool {
410410
// specification.
411411
return true
412412
}
413+
414+
// hasCapSysResource returns whether the current process has CAP_SYS_RESOURCE.
415+
func hasCapSysResource() (bool, error) {
416+
return true, nil
417+
}

libpod/container_internal_linux.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/containers/podman/v5/libpod/define"
2222
"github.com/containers/podman/v5/libpod/shutdown"
2323
"github.com/containers/podman/v5/pkg/rootless"
24+
"github.com/moby/sys/capability"
2425
spec "github.com/opencontainers/runtime-spec/specs-go"
2526
"github.com/opencontainers/runtime-tools/generate"
2627
"github.com/opencontainers/selinux/go-selinux/label"
@@ -835,3 +836,15 @@ func (c *Container) hasPrivateUTS() bool {
835836
}
836837
return privateUTS
837838
}
839+
840+
// hasCapSysResource returns whether the current process has CAP_SYS_RESOURCE.
841+
var hasCapSysResource = sync.OnceValues(func() (bool, error) {
842+
currentCaps, err := capability.NewPid2(0)
843+
if err != nil {
844+
return false, err
845+
}
846+
if err = currentCaps.Load(); err != nil {
847+
return false, err
848+
}
849+
return currentCaps.Get(capability.EFFECTIVE, capability.CAP_SYS_RESOURCE), nil
850+
})

0 commit comments

Comments
 (0)