summaryrefslogtreecommitdiff
path: root/pkg/rootless/rootless.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2020-10-02 08:53:54 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2020-10-02 08:53:54 +0200
commitbaef6eff36775dd3d1762e5821703fec22168ad7 (patch)
tree785d9ae28268b813cae460a72404ea06736f1cbf /pkg/rootless/rootless.go
parent54a9ecc2629093ca58050a8f7418908bc209cec5 (diff)
downloadpodman-baef6eff36775dd3d1762e5821703fec22168ad7.tar.gz
podman-baef6eff36775dd3d1762e5821703fec22168ad7.tar.bz2
podman-baef6eff36775dd3d1762e5821703fec22168ad7.zip
rootless: move GetAvailableGids to the rootless pkg
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/rootless/rootless.go')
-rw-r--r--pkg/rootless/rootless.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go
index d02721ea9..3c33597b6 100644
--- a/pkg/rootless/rootless.go
+++ b/pkg/rootless/rootless.go
@@ -4,6 +4,7 @@ import (
"os"
"github.com/containers/storage"
+ "github.com/opencontainers/runc/libcontainer/user"
"github.com/pkg/errors"
)
@@ -46,3 +47,17 @@ func TryJoinPauseProcess(pausePidPath string) (bool, int, error) {
}
return became, ret, err
}
+
+// GetAvailableGids returns how many GIDs are available in the
+// current user namespace.
+func GetAvailableGids() (int64, error) {
+ idMap, err := user.ParseIDMapFile("/proc/self/gid_map")
+ if err != nil {
+ return 0, err
+ }
+ count := int64(0)
+ for _, r := range idMap {
+ count += r.Count
+ }
+ return count, nil
+}