summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/common.go16
-rw-r--r--cmd/podman/container.go1
-rw-r--r--cmd/podman/create.go13
-rw-r--r--cmd/podman/exec.go29
-rw-r--r--cmd/podman/generate.go1
-rw-r--r--cmd/podman/healthcheck.go1
-rw-r--r--cmd/podman/image.go1
-rw-r--r--cmd/podman/images.go27
-rw-r--r--cmd/podman/main.go4
-rw-r--r--cmd/podman/play.go1
-rw-r--r--cmd/podman/pod.go1
-rw-r--r--cmd/podman/ps.go4
-rw-r--r--cmd/podman/system.go1
-rw-r--r--cmd/podman/trust.go1
-rw-r--r--cmd/podman/volume.go1
15 files changed, 70 insertions, 32 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index 9cd1998c8..30eaa95d8 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
- "github.com/spf13/cobra"
"os"
"strings"
@@ -14,6 +13,7 @@ import (
"github.com/containers/storage"
"github.com/fatih/camelcase"
"github.com/pkg/errors"
+ "github.com/spf13/cobra"
)
var (
@@ -67,6 +67,16 @@ func noSubArgs(c *cobra.Command, args []string) error {
return nil
}
+func commandRunE() func(*cobra.Command, []string) error {
+ return func(cmd *cobra.Command, args []string) error {
+ if len(args) > 0 {
+ return errors.Errorf("unrecognized command `%s %s`\nTry '%s --help' for more information.", cmd.CommandPath(), args[0], cmd.CommandPath())
+ } else {
+ return errors.Errorf("missing command '%s COMMAND'\nTry '%s --help' for more information.", cmd.CommandPath(), cmd.CommandPath())
+ }
+ }
+}
+
// getAllOrLatestContainers tries to return the correct list of containers
// depending if --all, --latest or <container-id> is used.
// It requires the Context (c) and the Runtime (runtime). As different
@@ -311,7 +321,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"kernel-memory", "",
"Kernel memory limit (format: `<number>[<unit>]`, where unit = b, k, m or g)",
)
- createFlags.StringSliceP(
+ createFlags.StringArrayP(
"label", "l", []string{},
"Set metadata on container (default [])",
)
@@ -537,7 +547,7 @@ Description:
// This blocks the desplaying of the global options. The main podman
// command should not use this.
func UsageTemplate() string {
- return `Usage:{{if .Runnable}}
+ return `Usage:{{if (and .Runnable (not .HasAvailableSubCommands))}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
diff --git a/cmd/podman/container.go b/cmd/podman/container.go
index 0bcdf533a..8ad8d7a44 100644
--- a/cmd/podman/container.go
+++ b/cmd/podman/container.go
@@ -15,6 +15,7 @@ var (
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
+ RunE: commandRunE(),
},
}
diff --git a/cmd/podman/create.go b/cmd/podman/create.go
index 968b5586b..8a5d0cf73 100644
--- a/cmd/podman/create.go
+++ b/cmd/podman/create.go
@@ -592,7 +592,7 @@ func parseCreateOpts(ctx context.Context, c *cliconfig.PodmanCommand, runtime *l
}
// LABEL VARIABLES
- labels, err := getAllLabels(c.StringSlice("label-file"), c.StringSlice("label"))
+ labels, err := getAllLabels(c.StringSlice("label-file"), c.StringArray("label"))
if err != nil {
return nil, errors.Wrapf(err, "unable to process labels")
}
@@ -893,7 +893,16 @@ func joinOrCreateRootlessUserNamespace(createConfig *cc.CreateConfig, runtime *l
}
return false, -1, errors.Errorf("dependency container %s is not running", ctr.ID())
}
- return rootless.JoinNS(uint(pid), 0)
+
+ data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile)
+ if err != nil {
+ return false, -1, errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile)
+ }
+ 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))
}
}
return rootless.BecomeRootInUserNS()
diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go
index c3bcec2ec..e4cea1f5e 100644
--- a/cmd/podman/exec.go
+++ b/cmd/podman/exec.go
@@ -106,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
diff --git a/cmd/podman/generate.go b/cmd/podman/generate.go
index 773d625ee..197fd26a6 100644
--- a/cmd/podman/generate.go
+++ b/cmd/podman/generate.go
@@ -12,6 +12,7 @@ var (
Use: "generate",
Short: "Generated structured data",
Long: generateDescription,
+ RunE: commandRunE(),
}
)
diff --git a/cmd/podman/healthcheck.go b/cmd/podman/healthcheck.go
index e7cc125cc..48d6b6bbf 100644
--- a/cmd/podman/healthcheck.go
+++ b/cmd/podman/healthcheck.go
@@ -11,6 +11,7 @@ var healthcheckCommand = cliconfig.PodmanCommand{
Use: "healthcheck",
Short: "Manage Healthcheck",
Long: healthcheckDescription,
+ RunE: commandRunE(),
},
}
diff --git a/cmd/podman/image.go b/cmd/podman/image.go
index 57be7fe14..52bac6ecb 100644
--- a/cmd/podman/image.go
+++ b/cmd/podman/image.go
@@ -14,6 +14,7 @@ var (
Use: "image",
Short: "Manage images",
Long: imageDescription,
+ RunE: commandRunE(),
},
}
imagesSubCommand cliconfig.ImagesValues
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index 78dc87ad5..f92e5d44d 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -2,6 +2,7 @@ package main
import (
"context"
+ "fmt"
"reflect"
"sort"
"strings"
@@ -128,7 +129,7 @@ func init() {
func imagesCmd(c *cliconfig.ImagesValues) error {
var (
filterFuncs []imagefilters.ResultFilter
- newImage *adapter.ContainerImage
+ image string
)
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
@@ -137,23 +138,23 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
}
defer runtime.Shutdown(false)
if len(c.InputArgs) == 1 {
- newImage, err = runtime.NewImageFromLocal(c.InputArgs[0])
- if err != nil {
- return err
- }
+ image = c.InputArgs[0]
}
-
if len(c.InputArgs) > 1 {
return errors.New("'podman images' requires at most 1 argument")
}
-
+ if len(c.Filter) > 0 && image != "" {
+ return errors.New("can not specify an image and a filter")
+ }
ctx := getContext()
- if len(c.Filter) > 0 || newImage != nil {
- filterFuncs, err = CreateFilterFuncs(ctx, runtime, c.Filter, newImage)
- if err != nil {
- return err
- }
+ if len(c.Filter) > 0 {
+ filterFuncs, err = CreateFilterFuncs(ctx, runtime, c.Filter, nil)
+ } else {
+ filterFuncs, err = CreateFilterFuncs(ctx, runtime, []string{fmt.Sprintf("reference=%s", image)}, nil)
+ }
+ if err != nil {
+ return err
}
opts := imagesOptions{
@@ -174,7 +175,7 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
var filteredImages []*adapter.ContainerImage
//filter the images
- if len(c.Filter) > 0 || newImage != nil {
+ if len(c.Filter) > 0 || len(c.InputArgs) == 1 {
filteredImages = imagefilters.FilterImages(images, filterFuncs)
} else {
filteredImages = images
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 97ffa8930..7d4b650a9 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -82,9 +82,7 @@ var cmdsNotRequiringRootless = map[*cobra.Command]bool{
var rootCmd = &cobra.Command{
Use: "podman",
Long: "manage pods and images",
- RunE: func(cmd *cobra.Command, args []string) error {
- return cmd.Help()
- },
+ RunE: commandRunE(),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return before(cmd, args)
},
diff --git a/cmd/podman/play.go b/cmd/podman/play.go
index 2a0c41ef6..95eae653e 100644
--- a/cmd/podman/play.go
+++ b/cmd/podman/play.go
@@ -12,6 +12,7 @@ var (
Use: "play",
Short: "Play a pod",
Long: playDescription,
+ RunE: commandRunE(),
}
)
diff --git a/cmd/podman/pod.go b/cmd/podman/pod.go
index 315b2e7bc..2d9bca21d 100644
--- a/cmd/podman/pod.go
+++ b/cmd/podman/pod.go
@@ -13,6 +13,7 @@ var podCommand = cliconfig.PodmanCommand{
Use: "pod",
Short: "Manage pods",
Long: podDescription,
+ RunE: commandRunE(),
},
}
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index 9793d67f8..6caac2406 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -419,7 +419,7 @@ func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Ru
return false
}, nil
case "status":
- if !util.StringInSlice(filterValue, []string{"created", "restarting", "running", "paused", "exited", "unknown"}) {
+ if !util.StringInSlice(filterValue, []string{"created", "running", "paused", "exited", "unknown"}) {
return nil, errors.Errorf("%s is not a valid status", filterValue)
}
return func(c *libpod.Container) bool {
@@ -430,6 +430,8 @@ func generateContainerFilterFuncs(filter, filterValue string, runtime *libpod.Ru
state := status.String()
if status == libpod.ContainerStateConfigured {
state = "created"
+ } else if status == libpod.ContainerStateStopped {
+ state = "exited"
}
return state == filterValue
}, nil
diff --git a/cmd/podman/system.go b/cmd/podman/system.go
index 741b79da5..528a594de 100644
--- a/cmd/podman/system.go
+++ b/cmd/podman/system.go
@@ -13,6 +13,7 @@ var (
Use: "system",
Short: "Manage podman",
Long: systemDescription,
+ RunE: commandRunE(),
},
}
)
diff --git a/cmd/podman/trust.go b/cmd/podman/trust.go
index a412e9483..0a79e1570 100644
--- a/cmd/podman/trust.go
+++ b/cmd/podman/trust.go
@@ -14,6 +14,7 @@ var (
Use: "trust",
Short: "Manage container image trust policy",
Long: trustDescription,
+ RunE: commandRunE(),
},
}
)
diff --git a/cmd/podman/volume.go b/cmd/podman/volume.go
index efc0d7ac9..2a071d0c7 100644
--- a/cmd/podman/volume.go
+++ b/cmd/podman/volume.go
@@ -12,6 +12,7 @@ var volumeCommand = cliconfig.PodmanCommand{
Use: "volume",
Short: "Manage volumes",
Long: volumeDescription,
+ RunE: commandRunE(),
},
}
var volumeSubcommands = []*cobra.Command{