summaryrefslogtreecommitdiff
path: root/cmd/podman/exec.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/exec.go')
-rw-r--r--cmd/podman/exec.go35
1 files changed, 21 insertions, 14 deletions
diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go
index 32a6e4bb5..e4cea1f5e 100644
--- a/cmd/podman/exec.go
+++ b/cmd/podman/exec.go
@@ -17,10 +17,7 @@ import (
var (
execCommand cliconfig.ExecValues
- execDescription = `
- podman exec
-
- Run a command in a running container
+ execDescription = `Execute the specified command inside a running container.
`
_execCommand = &cobra.Command{
Use: "exec [flags] CONTAINER [COMMAND [ARG...]]",
@@ -39,6 +36,7 @@ var (
func init() {
execCommand.Command = _execCommand
+ execCommand.SetHelpTemplate(HelpTemplate())
execCommand.SetUsageTemplate(UsageTemplate())
flags := execCommand.Flags()
flags.SetInterspersed(false)
@@ -108,16 +106,25 @@ func execCmd(c *cliconfig.ExecValues) error {
}
- pid, err := ctr.PID()
- if err != nil {
- return err
- }
- became, ret, err := rootless.JoinNS(uint(pid), c.PreserveFDs)
- if err != nil {
- return err
- }
- if became {
- os.Exit(ret)
+ if os.Geteuid() != 0 {
+ var became bool
+ var ret int
+
+ data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile)
+ if err != nil {
+ return errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile)
+ }
+ conmonPid, err := strconv.Atoi(string(data))
+ if err != nil {
+ return errors.Wrapf(err, "cannot parse PID %q", data)
+ }
+ became, ret, err = rootless.JoinDirectUserAndMountNS(uint(conmonPid))
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
}
// ENVIRONMENT VARIABLES