aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-01-11 15:42:21 -0800
committerGitHub <noreply@github.com>2019-01-11 15:42:21 -0800
commit5c86efb28976938ad77fcc0f677e0842d06b65b5 (patch)
tree16cd8fcf81e9bc355b7b50648713ca09f5fa1bd2 /cmd
parent28c35cab8750f379a418e87ed6bd874a12ec158d (diff)
parent04a4ba9b7302b807b7a5d9a180d3fcd27560052a (diff)
downloadpodman-5c86efb28976938ad77fcc0f677e0842d06b65b5.tar.gz
podman-5c86efb28976938ad77fcc0f677e0842d06b65b5.tar.bz2
podman-5c86efb28976938ad77fcc0f677e0842d06b65b5.zip
Merge pull request #2138 from giuseppe/rootless-pod-fix
rootless: fix usage of create --pod=new:FOO
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/create.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go
index d98b78bd4..87fa18e47 100644
--- a/cmd/podman/create.go
+++ b/cmd/podman/create.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "io/ioutil"
"os"
"path/filepath"
"strconv"
@@ -421,6 +422,16 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
}
if c.IsSet("pod") {
if strings.HasPrefix(originalPodName, "new:") {
+ if rootless.IsRootless() {
+ // To create a new pod, we must immediately create the userns.
+ became, ret, err := rootless.BecomeRootInUserNS()
+ if err != nil {
+ return nil, err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ }
// pod does not exist; lets make it
var podOptions []libpod.PodCreateOption
podOptions = append(podOptions, libpod.WithPodName(podName), libpod.WithInfraContainer(), libpod.WithPodCgroups())
@@ -785,11 +796,15 @@ func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *l
if s != libpod.ContainerStateRunning && s != libpod.ContainerStatePaused {
continue
}
- pid, err := prevCtr.PID()
+ data, err := ioutil.ReadFile(prevCtr.Config().ConmonPidFile)
if err != nil {
- return false, -1, err
+ return false, -1, errors.Wrapf(err, "cannot read conmon PID file %q", prevCtr.Config().ConmonPidFile)
}
- return rootless.JoinNS(uint(pid))
+ conmonPid, err := strconv.Atoi(string(data))
+ if err != nil {
+ return false, -1, errors.Wrapf(err, "cannot parse PID %q", data)
+ }
+ return rootless.JoinDirectUserAndMountNS(uint(conmonPid))
}
}