diff options
Diffstat (limited to 'cmd/podman/main.go')
-rw-r--r-- | cmd/podman/main.go | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 5f740a006..007a8716c 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -4,19 +4,20 @@ import ( "fmt" "os" - _ "github.com/containers/libpod/v2/cmd/podman/containers" - _ "github.com/containers/libpod/v2/cmd/podman/generate" - _ "github.com/containers/libpod/v2/cmd/podman/healthcheck" - _ "github.com/containers/libpod/v2/cmd/podman/images" - _ "github.com/containers/libpod/v2/cmd/podman/manifest" - _ "github.com/containers/libpod/v2/cmd/podman/networks" - _ "github.com/containers/libpod/v2/cmd/podman/play" - _ "github.com/containers/libpod/v2/cmd/podman/pods" - "github.com/containers/libpod/v2/cmd/podman/registry" - _ "github.com/containers/libpod/v2/cmd/podman/system" - _ "github.com/containers/libpod/v2/cmd/podman/volumes" - "github.com/containers/libpod/v2/pkg/rootless" - "github.com/containers/libpod/v2/pkg/terminal" + _ "github.com/containers/podman/v2/cmd/podman/containers" + _ "github.com/containers/podman/v2/cmd/podman/generate" + _ "github.com/containers/podman/v2/cmd/podman/healthcheck" + _ "github.com/containers/podman/v2/cmd/podman/images" + _ "github.com/containers/podman/v2/cmd/podman/manifest" + _ "github.com/containers/podman/v2/cmd/podman/networks" + _ "github.com/containers/podman/v2/cmd/podman/play" + _ "github.com/containers/podman/v2/cmd/podman/pods" + "github.com/containers/podman/v2/cmd/podman/registry" + _ "github.com/containers/podman/v2/cmd/podman/system" + _ "github.com/containers/podman/v2/cmd/podman/system/connection" + _ "github.com/containers/podman/v2/cmd/podman/volumes" + "github.com/containers/podman/v2/pkg/rootless" + "github.com/containers/podman/v2/pkg/terminal" "github.com/containers/storage/pkg/reexec" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -39,13 +40,21 @@ func main() { for _, m := range c.Mode { if cfg.EngineMode == m { // Command cannot be run rootless - _, found := c.Command.Annotations[registry.ParentNSRequired] - if rootless.IsRootless() && found { - c.Command.RunE = func(cmd *cobra.Command, args []string) error { - return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath()) + _, found := c.Command.Annotations[registry.UnshareNSRequired] + if found { + if rootless.IsRootless() && found && os.Getuid() != 0 { + c.Command.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("cannot run command %q in rootless mode, must execute `podman unshare` first", cmd.CommandPath()) + } + } + } else { + _, found = c.Command.Annotations[registry.ParentNSRequired] + if rootless.IsRootless() && found { + c.Command.RunE = func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("cannot run command %q in rootless mode", cmd.CommandPath()) + } } } - parent := rootCmd if c.Parent != nil { parent = c.Parent |