From 4d097d1f67169014dfe53c066adac3a7e28c9288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 26 Jan 2020 18:40:54 +0100 Subject: [PATCH] Automatically execute podman-remote if vars set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If any of PODMAN_HOST or PODMAN_VARLINK_BRIDGE are set, then execute "podman-remote" rather than this "podman". Also support PODMAN_VARLINK_ADDRESS for tunneling, even though there is no encryption support in such addresses. Signed-off-by: Anders F Björklund --- cmd/podman/main_local.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmd/podman/main_local.go b/cmd/podman/main_local.go index e5b87754bd..fca2245267 100644 --- a/cmd/podman/main_local.go +++ b/cmd/podman/main_local.go @@ -9,6 +9,7 @@ import ( "io/ioutil" "log/syslog" "os" + "os/exec" "runtime/pprof" "strconv" "strings" @@ -31,7 +32,37 @@ import ( const remote = false +func runRemote(path string, args ...string) (int, error) { + c := exec.Command(path, args...) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + c.Stderr = os.Stderr + if err := c.Run(); err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + waitStatus := exitError.Sys().(syscall.WaitStatus) + return waitStatus.ExitStatus(), nil + } + return 1, err + } + return 0, nil +} + func init() { + host := os.Getenv("PODMAN_HOST") + bridge := os.Getenv("PODMAN_VARLINK_BRIDGE") + address := os.Getenv("PODMAN_VARLINK_ADDRESS") + if host != "" || bridge != "" || address != "" { + program := "podman-remote" + if path, err := exec.LookPath(program); err == nil { + if rc, err := runRemote(path, os.Args[1:]...); err == nil { + os.Exit(rc) + } else { + fmt.Fprintf(os.Stderr, "Error running %s: %v\n", path, err) + } + } else { + fmt.Fprintf(os.Stderr, "Error finding %s: %v\n", program, err) + } + } cgroupManager := define.SystemdCgroupsManager cgroupHelp := `Cgroup manager to use ("cgroupfs"|"systemd")` cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()