diff options
Diffstat (limited to 'pkg/rootless')
-rw-r--r-- | pkg/rootless/rootless.go | 43 | ||||
-rw-r--r-- | pkg/rootless/rootless_linux.go | 32 |
2 files changed, 31 insertions, 44 deletions
diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go deleted file mode 100644 index ca851f9bc..000000000 --- a/pkg/rootless/rootless.go +++ /dev/null @@ -1,43 +0,0 @@ -package rootless - -import ( - "fmt" - "github.com/containers/storage/pkg/idtools" - "os" - "os/exec" -) - -/* -extern int reexec_in_user_namespace(int ready); -extern int reexec_in_user_namespace_wait(int pid); -*/ -import "C" - -func runInUser() error { - os.Setenv("_LIBPOD_USERNS_CONFIGURED", "done") - return nil -} - -func tryMappingTool(tool string, pid int, hostID int, mappings []idtools.IDMap) error { - path, err := exec.LookPath(tool) - if err != nil { - return err - } - - appendTriplet := func(l []string, a, b, c int) []string { - return append(l, fmt.Sprintf("%d", a), fmt.Sprintf("%d", b), fmt.Sprintf("%d", c)) - } - - args := []string{path, fmt.Sprintf("%d", pid)} - args = appendTriplet(args, 0, hostID, 1) - if mappings != nil { - for _, i := range mappings { - args = appendTriplet(args, i.ContainerID+1, i.HostID, i.Size) - } - } - cmd := exec.Cmd{ - Path: path, - Args: args, - } - return cmd.Run() -} diff --git a/pkg/rootless/rootless_linux.go b/pkg/rootless/rootless_linux.go index 70fa6b152..55a55bbc6 100644 --- a/pkg/rootless/rootless_linux.go +++ b/pkg/rootless/rootless_linux.go @@ -1,4 +1,4 @@ -// build +linux +// +build linux package rootless @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "os" + "os/exec" gosignal "os/signal" "runtime" "strconv" @@ -22,6 +23,11 @@ extern int reexec_in_user_namespace_wait(int pid); */ import "C" +func runInUser() error { + os.Setenv("_LIBPOD_USERNS_CONFIGURED", "done") + return nil +} + // IsRootless tells us if we are running in rootless mode func IsRootless() bool { return os.Getuid() != 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != "" @@ -37,6 +43,30 @@ func GetRootlessUID() int { return os.Getuid() } +func tryMappingTool(tool string, pid int, hostID int, mappings []idtools.IDMap) error { + path, err := exec.LookPath(tool) + if err != nil { + return err + } + + appendTriplet := func(l []string, a, b, c int) []string { + return append(l, fmt.Sprintf("%d", a), fmt.Sprintf("%d", b), fmt.Sprintf("%d", c)) + } + + args := []string{path, fmt.Sprintf("%d", pid)} + args = appendTriplet(args, 0, hostID, 1) + if mappings != nil { + for _, i := range mappings { + args = appendTriplet(args, i.ContainerID+1, i.HostID, i.Size) + } + } + cmd := exec.Cmd{ + Path: path, + Args: args, + } + return cmd.Run() +} + // BecomeRootInUserNS re-exec podman in a new userNS func BecomeRootInUserNS() (bool, error) { |