aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-12 19:55:15 +0200
committerGitHub <noreply@github.com>2022-09-12 19:55:15 +0200
commit6e545945a562b0116aa18ab0f38b36c59166838e (patch)
tree0dd37a72a795a61dcda08423d7aeac37e9ba5c94 /cmd
parent8432ed7488e9c62738f9308fcc03f2ae9c2cd615 (diff)
parenta63a40c3eece95e96e5b52a00646998606c5f82c (diff)
downloadpodman-6e545945a562b0116aa18ab0f38b36c59166838e.tar.gz
podman-6e545945a562b0116aa18ab0f38b36c59166838e.tar.bz2
podman-6e545945a562b0116aa18ab0f38b36c59166838e.zip
Merge pull request #15717 from Luap99/events
fix several podman events issues
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/system/events.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go
index 3c6a35e83..290f5b0fa 100644
--- a/cmd/podman/system/events.go
+++ b/cmd/podman/system/events.go
@@ -99,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
}