diff options
Diffstat (limited to 'cmd/podman/system/events.go')
-rw-r--r-- | cmd/podman/system/events.go | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index b04668f86..290f5b0fa 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -85,7 +85,9 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { doJSON = report.IsJSON(eventFormat) if !doJSON { var err error - rpt, err = report.New(os.Stdout, cmd.Name()).Parse(report.OriginUser, eventFormat) + // Use OriginUnknown so it does not add an extra range since it + // will only be called for each single element and not a slice. + rpt, err = report.New(os.Stdout, cmd.Name()).Parse(report.OriginUnknown, eventFormat) if err != nil { return err } @@ -97,25 +99,33 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { errChannel <- err }() - for event := range eventChannel { - switch { - case event == nil: - // no-op - case doJSON: - jsonStr, err := event.ToJSONString() - if err != nil { - return err + for { + select { + case event, ok := <-eventChannel: + if !ok { + // channel was closed we can exit + return nil + } + switch { + case doJSON: + jsonStr, err := event.ToJSONString() + if err != nil { + return err + } + fmt.Println(jsonStr) + case cmd.Flags().Changed("format"): + if err := rpt.Execute(event); err != nil { + return err + } + default: + fmt.Println(event.ToHumanReadable(!noTrunc)) } - fmt.Println(jsonStr) - case cmd.Flags().Changed("format"): - if err := rpt.Execute(event); err != nil { + case err := <-errChannel: + // only exit in case of an error, + // otherwise keep reading events until the event channel is closed + if err != nil { return err } - os.Stdout.WriteString("\n") - default: - fmt.Println(event.ToHumanReadable(!noTrunc)) } } - - return <-errChannel } |