Skip to content

Commit

Permalink
Fix --tail log on restart problem
Browse files Browse the repository at this point in the history
--tail=1 is not working f you restart a container with journald logging.

We see the exit status and then call into the logging a second time
causing all of the logs to print.

Removing the tail log on exited seems to fix the problem.

Fixes: #13098

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Apr 13, 2022
1 parent 8586b48 commit ac8a7c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions libpod/container_log_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
containerCouldBeLogging = true
case events.Exited:
containerCouldBeLogging = false
if doTail {
doTailFunc()
}
}
continue
}
Expand Down
17 changes: 17 additions & 0 deletions test/system/035-logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ load helpers
run_podman rm $cid
}

@test "podman logs - tail test" {
rand_string=$(random_string 40)

run_podman run -d $IMAGE sh -c "echo test1; echo test2"
cid="$output"

run_podman logs --tail 1 $cid
is "$output" "test2" "logs should only show last line"

run_podman restart $cid

run_podman logs --tail 1 $cid
is "$output" "test2" "logs should only show last line"

run_podman rm $cid
}

function _additional_events_backend() {
local driver=$1
# Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend.
Expand Down

0 comments on commit ac8a7c3

Please sign in to comment.