diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/info.go | 36 | ||||
-rw-r--r-- | libpod/oci_linux.go | 30 | ||||
-rw-r--r-- | libpod/util.go | 37 |
3 files changed, 73 insertions, 30 deletions
diff --git a/libpod/info.go b/libpod/info.go index 9ab6f7e52..e5132b5f6 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" "runtime" "strconv" "strings" @@ -17,6 +18,7 @@ import ( "github.com/containers/storage" "github.com/containers/storage/pkg/system" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // top-level "host" info @@ -44,6 +46,20 @@ func (r *Runtime) hostInfo() (map[string]interface{}, error) { "package": r.defaultOCIRuntime.conmonPackage(), "version": conmonVersion, } + if rootless.IsRootless() { + if path, err := exec.LookPath("slirp4netns"); err == nil { + logrus.Warnf("Failed to retrieve program version for %s: %v", path, err) + version, err := programVersion(path) + if err != nil { + logrus.Warnf("Failed to retrieve program version for %s: %v", path, err) + } + program := map[string]interface{}{} + program["Executable"] = path + program["Version"] = version + program["Package"] = packageVersion(path) + info["slirp4netns"] = program + } + } info["OCIRuntime"] = map[string]interface{}{ "path": r.defaultOCIRuntime.path, "package": r.defaultOCIRuntime.pathPackage(), @@ -53,7 +69,6 @@ func (r *Runtime) hostInfo() (map[string]interface{}, error) { "distribution": hostDistributionInfo["Distribution"], "version": hostDistributionInfo["Version"], } - info["BuildahVersion"] = buildah.Version kv, err := readKernelVersion() if err != nil { @@ -113,7 +128,24 @@ func (r *Runtime) storeInfo() (map[string]interface{}, error) { info["GraphRoot"] = r.store.GraphRoot() info["RunRoot"] = r.store.RunRoot() info["GraphDriverName"] = r.store.GraphDriverName() - info["GraphOptions"] = r.store.GraphOptions() + graphOptions := map[string]interface{}{} + for _, o := range r.store.GraphOptions() { + split := strings.SplitN(o, "=", 2) + if strings.HasSuffix(split[0], "mount_program") { + version, err := programVersion(split[1]) + if err != nil { + logrus.Warnf("Failed to retrieve program version for %s: %v", split[1], err) + } + program := map[string]interface{}{} + program["Executable"] = split[1] + program["Version"] = version + program["Package"] = packageVersion(split[1]) + graphOptions[split[0]] = program + } else { + graphOptions[split[0]] = split[1] + } + } + info["GraphOptions"] = graphOptions info["VolumePath"] = r.config.VolumePath configFile, err := storage.DefaultConfigFile(rootless.IsRootless()) diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go index 1613c3e68..6dba1260c 100644 --- a/libpod/oci_linux.go +++ b/libpod/oci_linux.go @@ -24,8 +24,6 @@ import ( "k8s.io/client-go/tools/remotecommand" ) -const unknownPackage = "Unknown" - // makeAccessible changes the path permission and each parent directory to have --x--x--x func makeAccessible(path string, uid, gid int) error { for ; path != "/"; path = filepath.Dir(path) { @@ -114,36 +112,12 @@ func (r *OCIRuntime) createContainer(ctr *Container, restoreOptions *ContainerCh return r.createOCIContainer(ctr, restoreOptions) } -func rpmVersion(path string) string { - output := unknownPackage - cmd := exec.Command("/usr/bin/rpm", "-q", "-f", path) - if outp, err := cmd.Output(); err == nil { - output = string(outp) - } - return strings.Trim(output, "\n") -} - -func dpkgVersion(path string) string { - output := unknownPackage - cmd := exec.Command("/usr/bin/dpkg", "-S", path) - if outp, err := cmd.Output(); err == nil { - output = string(outp) - } - return strings.Trim(output, "\n") -} - func (r *OCIRuntime) pathPackage() string { - if out := rpmVersion(r.path); out != unknownPackage { - return out - } - return dpkgVersion(r.path) + return packageVersion(r.path) } func (r *OCIRuntime) conmonPackage() string { - if out := rpmVersion(r.conmonPath); out != unknownPackage { - return out - } - return dpkgVersion(r.conmonPath) + return packageVersion(r.conmonPath) } // execContainer executes a command in a running container diff --git a/libpod/util.go b/libpod/util.go index 164800af4..84fd490bf 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -3,6 +3,7 @@ package libpod import ( "fmt" "os" + "os/exec" "path/filepath" "sort" "strconv" @@ -10,6 +11,7 @@ import ( "time" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/utils" "github.com/fsnotify/fsnotify" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -20,6 +22,8 @@ const ( // DefaultTransport is a prefix that we apply to an image name // to check docker hub first for the image DefaultTransport = "docker://" + + unknownPackage = "Unknown" ) // FuncTimer helps measure the execution time of a function @@ -152,3 +156,36 @@ func JSONDeepCopy(from, to interface{}) error { } return json.Unmarshal(tmp, to) } + +func dpkgVersion(path string) string { + output := unknownPackage + cmd := exec.Command("/usr/bin/dpkg", "-S", path) + if outp, err := cmd.Output(); err == nil { + output = string(outp) + } + return strings.Trim(output, "\n") +} + +func rpmVersion(path string) string { + output := unknownPackage + cmd := exec.Command("/usr/bin/rpm", "-q", "-f", path) + if outp, err := cmd.Output(); err == nil { + output = string(outp) + } + return strings.Trim(output, "\n") +} + +func packageVersion(program string) string { + if out := rpmVersion(program); out != unknownPackage { + return out + } + return dpkgVersion(program) +} + +func programVersion(mountProgram string) (string, error) { + output, err := utils.ExecCmd(mountProgram, "--version") + if err != nil { + return "", err + } + return strings.TrimSuffix(output, "\n"), nil +} |