Files
podman/pkg/util/utils_linux.go
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00

71 lines
1.9 KiB
Go

package util
import (
"fmt"
"os"
"path/filepath"
"syscall"
"github.com/containers/libpod/v2/pkg/rootless"
"github.com/containers/psgo"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// GetContainerPidInformationDescriptors returns a string slice of all supported
// format descriptors of GetContainerPidInformation.
func GetContainerPidInformationDescriptors() ([]string, error) {
return psgo.ListDescriptors(), nil
}
// FindDeviceNodes parses /dev/ into a set of major:minor -> path, where
// [major:minor] is the device's major and minor numbers formatted as, for
// example, 2:0 and path is the path to the device node.
// Symlinks to nodes are ignored.
func FindDeviceNodes() (map[string]string, error) {
nodes := make(map[string]string)
err := filepath.Walk("/dev", func(path string, info os.FileInfo, err error) error {
if err != nil {
logrus.Warnf("Error descending into path %s: %v", path, err)
return filepath.SkipDir
}
// If we aren't a device node, do nothing.
if info.Mode()&(os.ModeDevice|os.ModeCharDevice) == 0 {
return nil
}
// We are a device node. Get major/minor.
sysstat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return errors.Errorf("Could not convert stat output for use")
}
major := sysstat.Rdev / 256
minor := sysstat.Rdev % 256
nodes[fmt.Sprintf("%d:%d", major, minor)] = path
return nil
})
if err != nil {
return nil, err
}
return nodes, nil
}
// CheckRootlessUIDRange checks the uid within the rootless container is in the range from /etc/subuid
func CheckRootlessUIDRange(uid int) error {
uids, _, err := rootless.GetConfiguredMappings()
if err != nil {
return err
}
for _, u := range uids {
// add 1 since we also map in the user's own UID
if uid > u.Size+1 {
return errors.Errorf("requested user's UID %d is too large for the rootless user namespace", uid)
}
}
return nil
}