diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-10-02 14:45:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-02 14:45:27 -0400 |
commit | 1e162edc8a2dd3d8373128e671c578ffcad52272 (patch) | |
tree | b94f581c888c0bf283e41146b35f12d87a113dc0 /pkg/rootless | |
parent | 819a4e02888b92c3120f513f398993a165f69028 (diff) | |
parent | d30121969f0ba7b16700238b876a6bba7417875a (diff) | |
download | podman-1e162edc8a2dd3d8373128e671c578ffcad52272.tar.gz podman-1e162edc8a2dd3d8373128e671c578ffcad52272.tar.bz2 podman-1e162edc8a2dd3d8373128e671c578ffcad52272.zip |
Merge pull request #7882 from giuseppe/check-for-gids-before-adding-them
libpod: check there are enough gids before adding them
Diffstat (limited to 'pkg/rootless')
-rw-r--r-- | pkg/rootless/rootless.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go index d02721ea9..799c793d8 100644 --- a/pkg/rootless/rootless.go +++ b/pkg/rootless/rootless.go @@ -2,8 +2,10 @@ package rootless import ( "os" + "sync" "github.com/containers/storage" + "github.com/opencontainers/runc/libcontainer/user" "github.com/pkg/errors" ) @@ -46,3 +48,26 @@ func TryJoinPauseProcess(pausePidPath string) (bool, int, error) { } return became, ret, err } + +var ( + availableGids int64 + availableGidsErr error + availableGidsOnce sync.Once +) + +// GetAvailableGids returns how many GIDs are available in the +// current user namespace. +func GetAvailableGids() (int64, error) { + availableGidsOnce.Do(func() { + idMap, err := user.ParseIDMapFile("/proc/self/gid_map") + if err != nil { + availableGidsErr = err + return + } + availableGids = int64(0) + for _, r := range idMap { + availableGids += r.Count + } + }) + return availableGids, availableGidsErr +} |