diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-07-18 09:23:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-18 09:23:47 +0200 |
commit | 7488ed6d9a619d86333dc1880d4df034fbb371b9 (patch) | |
tree | 369e340cfc6ae08b62555a9fe1e4db4d0deae5eb /pkg/util/utils_linux.go | |
parent | b2734baee5637ec4440a40cca8ff5ebab377739f (diff) | |
parent | c91bc31570f1fab616e10d0e2b4a6c8b7fe631c7 (diff) | |
download | podman-7488ed6d9a619d86333dc1880d4df034fbb371b9.tar.gz podman-7488ed6d9a619d86333dc1880d4df034fbb371b9.tar.bz2 podman-7488ed6d9a619d86333dc1880d4df034fbb371b9.zip |
Merge pull request #3522 from mheon/nix_the_artifact
Move the HostConfig portion of Inspect inside libpod
Diffstat (limited to 'pkg/util/utils_linux.go')
-rw-r--r-- | pkg/util/utils_linux.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/pkg/util/utils_linux.go b/pkg/util/utils_linux.go index 47fa1031f..318bd2b1b 100644 --- a/pkg/util/utils_linux.go +++ b/pkg/util/utils_linux.go @@ -1,7 +1,14 @@ package util import ( + "fmt" + "os" + "path/filepath" + "syscall" + "github.com/containers/psgo" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // GetContainerPidInformationDescriptors returns a string slice of all supported @@ -9,3 +16,39 @@ import ( 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 := uint64(sysstat.Rdev / 256) + minor := uint64(sysstat.Rdev % 256) + + nodes[fmt.Sprintf("%d:%d", major, minor)] = path + + return nil + }) + if err != nil { + return nil, err + } + + return nodes, nil +} |